craftcms / element-api

Create a JSON API/Feed for your elements in Craft.
MIT License
498 stars 56 forks source link

404 #121

Closed AshtonKem closed 2 years ago

AshtonKem commented 4 years ago

It does not appear like this plugin is working with CraftCMS 3.3.X, as I am only getting a 404 when requesting this API.

element-api.php

<?php
use craft\elements\Entry;
use craft\helpers\UrlHelper;

return [
    'endpoints' => [
        'api/articles.json' => function() {
            return [
                'elementType' => Entry::class,
                'criteria' => ['section' => 'articles'],
                'transformer' => function(Entry $entry) {
                    return [
                        'title' => $entry->title,
                        'url' => $entry->url
                    ];
                },
            ];
        },
    ]
];
AshtonKem commented 4 years ago

I figured it out, it looks like having .json at the end of the endpoint causes the 404. Changing the above to api/articles fixes it.

ul8 commented 4 years ago

I am getting the same issue - previously working API endpoints do no longer work after updating to 3.3.x

@AshtonKem are you sure about your fix, is that really the only thing you changed? It seems very odd that the ".json" should have any negative impact. I tried the same but that didn't fix it.

AshtonKem commented 4 years ago

That is the only thing I changed, and it fixed the issue for me.

bertheyman commented 4 years ago

Can confirm this bug. Working with element api 2.6.0 and Craft 3.4.17. Endpoint returns 404 (with or without .json).

@brandonkelly, do you have a fix you can recommend?

ul8 commented 4 years ago

@bertheyman I don't remember what exactly it was, but for me this issue was ultimately caused by some custom module or other plugin code. I recommend you disable all plugins and modules and see if that helps to isolate it.

bertheyman commented 4 years ago

@ul8 Indeed, was an overlooked issue on our side. Thanks! @AshtonKem Did you get to solve your problem? Can the issue be closed?

AshtonKem commented 4 years ago

I no longer work at the company where I had this issue, so I don’t have the source necessary to reproduce.

— Ashton Kemerling

Sent from my iPhone.

On May 18, 2020, at 7:55 AM, Bert Heyman notifications@github.com wrote:

 @ul8 Indeed, was an overlooked issue on our side. Thanks! @AshtonKem Did you get to solve your problem? Can the issue be closed?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.