-
-
Notifications
You must be signed in to change notification settings - Fork 204
[v2.0.17] Example of API custom endpoint not working #762
Comments
Thanks @gnh1201 for reporting this, I am going to give this a look. |
I wasn't unable to reproduce it either on In the other hand, I am experiencing this bug, when the path doesn't exists: {
"error": {
"code": null,
"message": "Too few arguments to function Directus\\Application\\ErrorHandlers\\NotFoundHandler::__invoke(), 2 passed in /Users/welling/src/api/vendor/slim/slim/Slim/App.php on line 530 and exactly 3 expected",
"class": "ArgumentCountError",
"file": "/Users/welling/src/api/src/core/Directus/Application/ErrorHandlers/NotFoundHandler.php",
"line": 19
}
} |
Hello, I also was trying to make a call to example custom endpoint which code is located in public\extensions\custom\endpoints_example.php file. I've renamed _example.php to example.php and was trying to make an authenticated GET call to the following route: /myproject/custom/example. Error stack{ "error": { "code": null, "message": "Internal Server Error" } } And in logs I see the following error: [2019-02-11 13:51:29] api[casino].ERROR: ArgumentCountError: Too few arguments to function Directus\Application\ErrorHandlers\NotFoundHandler::__invoke(), 2 passed in D:\Git\github\directus\api\vendor\slim\slim\Slim\App.php on line 531 and exactly 3 expected in D:\Git\github\directus\api\src\core\Directus\Application\ErrorHandlers\NotFoundHandler.php:19 Stack trace: #0 D:\Git\github\directus\api\vendor\slim\slim\Slim\App.php(531): Directus\Application\ErrorHandlers\NotFoundHandler->__invoke #1 D:\Git\github\directus\api\src\core\Directus\Application\Http\Middleware\AbstractRateLimitMiddleware.php(34): Slim\App->__invoke #2 [internal function]: Directus\Application\Http\Middleware\AbstractRateLimitMiddleware->__invoke #3 D:\Git\github\directus\api\vendor\slim\slim\Slim\DeferredCallable.php(43): call_user_func_array #4 [internal function]: Slim\DeferredCallable->__invoke #5 D:\Git\github\directus\api\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(70): call_user_func #6 D:\Git\github\directus\api\vendor\wellingguzman\proxy-detection\src\ProxyDetectionMiddleware.php(30): Slim\App->Slim{closure} #7 D:\Git\github\directus\api\src\core\Directus\Application\Http\Middleware\ProxyMiddleware.php(18): RKA\Middleware\ProxyDetectionMiddleware->__invoke #8 [internal function]: Directus\Application\Http\Middleware\ProxyMiddleware->__invoke #9 D:\Git\github\directus\api\vendor\slim\slim\Slim\DeferredCallable.php(43): call_user_func_array #10 [internal function]: Slim\DeferredCallable->__invoke #11 D:\Git\github\directus\api\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(70): call_user_func #12 D:\Git\github\directus\api\vendor\akrabat\ip-address-middleware\src\IpAddress.php(113): Slim\App->Slim{closure} #13 [internal function]: RKA\Middleware\IpAddress->__invoke #14 D:\Git\github\directus\api\vendor\slim\slim\Slim\DeferredCallable.php(43): call_user_func_array #15 [internal function]: Slim\DeferredCallable->__invoke #16 D:\Git\github\directus\api\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(70): call_user_func #17 D:\Git\github\directus\api\src\core\Directus\Application\Http\Middleware\CorsMiddleware.php(66): Slim\App->Slim{closure} #18 [internal function]: Directus\Application\Http\Middleware\CorsMiddleware->__invoke #19 D:\Git\github\directus\api\vendor\slim\slim\Slim\DeferredCallable.php(43): call_user_func_array #20 [internal function]: Slim\DeferredCallable->__invoke #21 D:\Git\github\directus\api\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(70): call_user_func #22 D:\Git\github\directus\api\src\core\Directus\Application\Http\Middleware\ResponseCacheMiddleware.php(47): Slim\App->Slim{closure} #23 [internal function]: Directus\Application\Http\Middleware\ResponseCacheMiddleware->__invoke #24 D:\Git\github\directus\api\vendor\slim\slim\Slim\DeferredCallable.php(43): call_user_func_array #25 [internal function]: Slim\DeferredCallable->__invoke #26 D:\Git\github\directus\api\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(70): call_user_func #27 D:\Git\github\directus\api\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(117): Slim\App->Slim{closure} #28 D:\Git\github\directus\api\vendor\slim\slim\Slim\App.php(407): Slim\App->callMiddlewareStack #29 D:\Git\github\directus\api\vendor\slim\slim\Slim\App.php(315): Slim\App->process #30 D:\Git\github\directus\api\src\core\Directus\Application\Application.php(161): Slim\App->run #31 D:\Git\github\directus\api\public\index.php(5): Directus\Application\Application->run [] [] The API version is 2.0.17 |
@yarick2000 I am aware of that one, I will be fixing it soon. Although it seems you are not using the correct path to the endpoint. If you go to {
"data": [
"item 1",
"item 2"
]
} If you request an unknown endpoint even adding trailing slash Can you show me a screenshot of the request (url, headers, responses, etc) or the raw http request? |
Sorry that I just gave a route and not the full url. Here is what I was using: |
From your request/response, I can't tell where is the actual path of the request being made or the actual response (in json). I made a fix for the invalid third argument. At least that one should be fixed. If you were getting that error is likely you are going to get a Ref: 93b53bf |
So what other information you need from me in order to get more details about the issue? I see the changes you've made and understand they not fixing the issue but the error handler... |
Hey, sorry, I've figured out that directory endpoints are working for me, so the issue only with file endpoints (if file located right under custom/endpoints folder, like example.php) |
@wellingguzman — is there something we can add to the docs or example file to make this clearer? |
@benhaynes I think there's should be a issue on loading the files apparently, I don't think there's nothing we can make more clear about it. Well, because I don't actually know what the issue is here. @yarick2000 can you list the files in Also when you get the response back from the server click on the "headers" tab above the response "view". You can do this and share the screenshots for both directory and files endpoints, that way we can see the differences between both requests and help us narrow down the issue. |
Sorry, I didn't found the Generate Code Snippet there, but I can give a raw request/response print: For file endpoint (example.php): Except of example.php there is also .htaccess file under public/extensions/custom/endpoints and the folder with name 'directory' |
@yarick2000 you are still getting "Internal Server Error". can you share what's on your logs directory? Are you still getting the error below or is it something new?
|
I didn't change the version - I'm still on 2.0.17, so yes, I'm getting Internal Server Error. Was 2.0.18 already released? |
Hey @yarick2000, can you try testing the latest from Is the |
Hi, I will check the master when I will have time. Since I succeed with directory based endpoints this issue became less important for me. The name of example.php is lower cased - I just removed the underscore. |
Seems it is working fine on Mac and Linux systems, but not on Windows. The issue might be related to the |
Fixed in #961 |
Steps to Reproduce
I read the tutorial.
https://docs.directus.io/extensions/custom-endpoints.html#creating-custom-endpoints
I changed the name of the file
_example.php
in the/public/extensions/custom/endpoints/
directory toexample.php
.I tested the endpoint.
Can I see what I did wrong?
The text was updated successfully, but these errors were encountered: