"Bad request. No token or api key provided" - When connecting to mysql database via service

I have setup a remote MYSQL service with the following parameters via the dreamfactory web console.

Driver: MySQL

Connection String: mysql:host=xxx.xx.xx.xxx;port=3306;dbname=appcom_petapp

Username: appcom

Password:

Options and attributes I have left blank.

When I click on API docs I see the the created service. However, when I try to see the list of operations or expand operations nothing happens and when I click on “RAW” I get the following message:

{“error”:{“context”:null,“message”:“Bad request. No token or api key provided.”,“code”:400,“trace”:[“0 [internal function]: DreamFactory\Http\Middleware\AccessCheck->handle(Object(Illuminate\Http\Request), Object(Closure))”,“1 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)”,“2 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“3 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“4 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(114): Illuminate\Pipeline\Pipeline->then(Object(Closure))”,“5 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(69): Illuminate\Routing\ControllerDispatcher->callWithinStack(Object(DreamFactory\Http\Controllers\RestController), Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), ‘handleGET’)”,“6 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/laravel/framework/src/Illuminate/Routing/Route.php(201): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), ‘DreamFactory\Ht…’, ‘handleGET’)”,“7 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/laravel/framework/src/Illuminate/Routing/Route.php(134): Illuminate\Routing\Route->runWithCustomDispatcher(Object(Illuminate\Http\Request))”,“8 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/laravel/framework/src/Illuminate/Routing/Router.php(704): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))”,“9 [internal function]: Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))”,“10 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(139): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“11 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“12 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“13 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/laravel/framework/src/Illuminate/Routing/Router.php(706): Illuminate\Pipeline\Pipeline->then(Object(Closure))”,“14 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/laravel/framework/src/Illuminate/Routing/Router.php(671): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))”,“15 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/laravel/framework/src/Illuminate/Routing/Router.php(631): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))”,“16 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(236): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))”,“17 [internal function]: Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))”,“18 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(139): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“19 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/barryvdh/laravel-cors/src/HandleCors.php(43): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“20 [internal function]: Barryvdh\Cors\HandleCors->handle(Object(Illuminate\Http\Request), Object(Closure))”,“21 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)”,“22 /var/www/_releases/instance/dreamfactory/2.0.0-beta/app/Http/Middleware/FirstUserCheck.php(39): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“23 [internal function]: DreamFactory\Http\Middleware\FirstUserCheck->handle(Object(Illuminate\Http\Request), Object(Closure))”,“24 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)”,“25 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“26 [internal function]: Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))”,“27 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)”,“28 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(62): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“29 [internal function]: Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))”,“30 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)”,“31 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“32 [internal function]: Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))”,“33 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)”,“34 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(59): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“35 [internal function]: Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))”,“36 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)”,“37 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(42): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“38 [internal function]: Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))”,“39 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)”,“40 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“41 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“42 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(122): Illuminate\Pipeline\Pipeline->then(Object(Closure))”,“43 /var/www/_releases/instance/dreamfactory/2.0.0-beta/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(87): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))”,“44 /var/www/_releases/instance/dreamfactory/2.0.0-beta/public/index.php(53): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))”,“45 {main}”]}}

I am not sure what this means. I am not even confident if the service is able to connect to my database. The database here has a user that can access all information and no where have I provided the username and password for that database.I have provided the username and password that I have given in MySQL Workbench to connect to my remote server. Any idea what I am doing wrong ?

Thank you.

The “Raw” option in Swagger doesn’t work, this is a known issue. It’s already fixed in the repository, though it may be in the develop branch. You may continue to use API Docs without the “Raw” function to avoid the error, and call the API at /api/v2/api_docs if you need the raw JSON for all services, or /api/v2/api_docs/{servicename} if you want just the raw JSON for a single service.

That’s irrelevant to your MySQL connection issue. What’s logged in the DreamFactory log when the connection attempt fails?

I am facing same issue.
I tried link http://localhost/api/v2/TestAPIServer?as_list=true
It gave following error.
{“error”:{“context”:null,“message”:“Bad request. No token or api key provided.”,“code”:400,“trace”:[“0 [internal function]: DreamFactory\Http\Middleware\AccessCheck->handle(Object(Illuminate\Http\Request), Object(Closure))”,“1 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(9464): call_user_func_array(Array, Array)”,“2 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“3 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(9454): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“4 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(8816): Illuminate\Pipeline\Pipeline->then(Object(Closure))”,“5 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(8801): Illuminate\Routing\ControllerDispatcher->callWithinStack(Object(DreamFactory\Http\Controllers\RestController), Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), ‘handleGET’)”,“6 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(7755): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), ‘DreamFactory\\Ht…’, ‘handleGET’)”,“7 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(7726): Illuminate\Routing\Route->runWithCustomDispatcher(Object(Illuminate\Http\Request))”,“8 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(7379): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))”,“9 [internal function]: Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))”,“10 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(9472): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“11 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“12 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(9454): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“13 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(7380): Illuminate\Pipeline\Pipeline->then(Object(Closure))”,“14 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(7368): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))”,“15 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(7353): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))”,“16 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(2262): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))”,“17 [internal function]: Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))”,“18 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(9472): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“19 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\vendor\barryvdh\laravel-cors\src\HandleCors.php(43): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“20 [internal function]: Barryvdh\Cors\HandleCors->handle(Object(Illuminate\Http\Request), Object(Closure))”,“21 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(9464): call_user_func_array(Array, Array)”,“22 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(17836): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“23 [internal function]: DreamFactory\Http\Middleware\FirstUserCheck->handle(Object(Illuminate\Http\Request), Object(Closure))”,“24 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(9464): call_user_func_array(Array, Array)”,“25 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(12789): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“26 [internal function]: Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))”,“27 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(9464): call_user_func_array(Array, Array)”,“28 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(11412): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“29 [internal function]: Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))”,“30 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(9464): call_user_func_array(Array, Array)”,“31 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(12530): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“32 [internal function]: Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))”,“33 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(9464): call_user_func_array(Array, Array)”,“34 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(12469): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“35 [internal function]: Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))”,“36 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(9464): call_user_func_array(Array, Array)”,“37 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(2936): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“38 [internal function]: Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))”,“39 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(9464): call_user_func_array(Array, Array)”,“40 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“41 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(9454): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“42 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(2209): Illuminate\Pipeline\Pipeline->then(Object(Closure))”,“43 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\bootstrap\cache\compiled.php(2192): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))”,“44 C:\Bitnami\dreamfactory-2.0.beta-3\apps\dreamfactory\htdocs\public\index.php(53): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))”,“45 {main}”]}}

Am I missing anything ?.

Thanks

Hello @pradnesh_raut_cms, you made the request from the API docs? if you have not, enter the api_key parameter in the URL or X-DreamFactory-API-Key in the header.

Take a look API - DreamFactory

Best regards.

1 Like

Thanks a lot juniorconte, It worked.