The url: https://www.fira.co.uk/fullmembers.json

is an endpoint for Craft's element API plugin.

It has been working fine until recently I did a few things:

  • I changed the site to https
  • There have been some tweaks to the server config (nginx caching etc)

The problem I am having is that the URL returns a 404 header but still displays the JSON response in the browser. This 404 is affecting my wget script that systematically saves the response to a static file, as to improve performance.

Any ideas why the endpoint would be behaving like this?

I haven't altered the elementapi.php recently but here it is:

namespace Craft;

return [
    'endpoints' => [
        'fullmembers.json' => [
            'elementType' => 'User',
            'criteria' => ['group' => 'fullMembership', 'limit' => null, 'order' => 'companyName'],
            'paginate' => false,
            'transformer' => function(UserModel $member) {
                // var_dump($member->memberAddress);
                $businessCategories = [];
                foreach ($member->businessTypeMarketSectorsProducts as $block) {
                    switch ($block->type->handle) {
                        case 'businessCategory':

                        $productValues = [];
                        foreach ($block->product as $prod) {
                            if ($prod->selected) {
                                $productValues[] = $prod->value;

                        $businessCategories[] = [
                            'businessType' => $block->businessType->value,
                            'marketSector' => $block->marketSector->value,
                            'product' => $productValues

                // $urlslug = strtolower(implode('-',explode(" ", $member->membersCompanyName)));
                $urlslug = StringHelper::toKebabCase($member->membersCompanyName);

                return [
                    'id' => $member->id,
                    'companyName' => $member->membersCompanyName,
                    // 'memberAddress' => $member->memberAddress->attributes,
                    'lat' => $member->memberAddress->lat,
                    'lng' => $member->memberAddress->lng,
                    'city' => $member->memberAddress->city,
                    'street1' => $member->memberAddress->street1,
                    'street2' => $member->memberAddress->street2,
                    'street3' => $member->membersAddressLine3,
                    'zip' => $member->memberAddress->zip,
                    'country' => $member->memberAddress->country,
                    'email' => $member->email,
                    'phone' => $member->membersPhoneNumber,
                    'profile' => UrlHelper::getUrl("directory/company/{$member->id}/{$urlslug}"),
                    'businessCategories' => $businessCategories
  • I think it's pretty unlikely that Craft or the ElementAPI plugin is adding the 404 header given that we haven't heard of any other issue like this and it started occurring after server config tweaks. I'd start checking your nginx.conf file or anything else that might be adding the header (Varnish? Cloudflare? Some proxy server?) – Brad Bell Jul 9 '16 at 4:40

Removing this from my site's nginx conf fixed it:

location ~* \.(?:manifest|appcache|html?|xml|json)$ {
 expires -1;

However, what I really want to do is cache stuff, without breaking this endpoint


Updating the following line in our NGINX configuration also fixed the problem, this is similar to expires -1:


# cache.appcache, your document html and data
location ~* \.(?:manifest|appcache|html?|xml|json)$ {
  add_header Cache-Control "max-age=0";


# cache.appcache, your document html and data
location ~* \.(?:manifest|appcache|html?|xml)$ {
  add_header Cache-Control "max-age=0";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.