Calling SQL Service Rest endpoint from custom server script not working in Node JS

Hey,

Trying to fetch contents of the table in a custom script in Node JS. Below is the code

var cartId = event.request.payload.cartId;
var filter = ‘cartId=’+ cartId;
var related = ‘cart_line_item_by_cart_id’;
var options = {
‘headers’: {
‘Content-Type’: ‘application/json’,
‘X-DreamFactory-Api-Key’: ‘259124c07a7ad030582b8eb185431ba2bdd8265b3353b690c533c91dce4e3e08’//mock key
}
};
platform.api.get(‘kw2-sql-db/_table/cart’, options, function(body, response) {
console.log(‘body’ + body);
console.log(‘response’ + response);
// this call actually has failed. mentioning the body below
});

Logs

body{“error”:{“context”:null,“message”:“Invalid token: Wrong number of segments”,“code”:401,“trace”:[“0 [internal function]: DreamFactory\Http\Middleware\AccessCheck->handle(Object(Illuminate\Http\Request), Object(Closure))”,“1 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9963): call_user_func_array(Array, Array)”,“2 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“3 /opt/bitnami/apps/dreamfactory/htdocs/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“4 [internal function]: Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))”,“5 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9948): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“6 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9467): Illuminate\Pipeline\Pipeline->then(Object(Closure))”,“7 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9454): Illuminate\Routing\ControllerDispatcher->callWithinStack(Object(DreamFactory\Http\Controllers\RestController), Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), ‘handleGET’)”,“8 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8524): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), ‘DreamFactory\\Ht…’, ‘handleGET’)”,“9 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8511): Illuminate\Routing\Route->runController(Object(Illuminate\Http\Request))”,“10 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8225): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))”,“11 [internal function]: Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))”,“12 /opt/bitnami/apps/dreamfactory/htdocs/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(52): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“13 [internal function]: Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))”,“14 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9948): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“15 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8226): Illuminate\Pipeline\Pipeline->then(Object(Closure))”,“16 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8217): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))”,“17 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8207): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))”,“18 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(2419): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))”,“19 [internal function]: Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))”,“20 /opt/bitnami/apps/dreamfactory/htdocs/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(52): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“21 /opt/bitnami/apps/dreamfactory/htdocs/app/Http/Middleware/AuthCheck.php(183): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))”,“22 [internal function]: DreamFactory\Http\Middleware\AuthCheck->handle(Object(Illuminate\Http\Request), Object(Closure))”,“23 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9963): call_user_func_array(Array, Array)”,“24 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“25 /opt/bitnami/apps/dreamfactory/htdocs/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“26 /opt/bitnami/apps/dreamfactory/htdocs/vendor/barryvdh/laravel-cors/src/HandleCors.php(34): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))”,“27 [internal function]: Barryvdh\Cors\HandleCors->handle(Object(Illuminate\Http\Request), Object(Closure))”,“28 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9963): call_user_func_array(Array, Array)”,“29 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“30 /opt/bitnami/apps/dreamfactory/htdocs/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“31 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(17769): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))”,“32 [internal function]: DreamFactory\Http\Middleware\FirstUserCheck->handle(Object(Illuminate\Http\Request), Object(Closure))”,“33 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9963): call_user_func_array(Array, Array)”,“34 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“35 /opt/bitnami/apps/dreamfactory/htdocs/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“36 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(13474): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))”,“37 [internal function]: Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))”,“38 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9963): call_user_func_array(Array, Array)”,“39 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“40 /opt/bitnami/apps/dreamfactory/htdocs/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“41 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(11964): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))”,“42 [internal function]: Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))”,“43 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9963): call_user_func_array(Array, Array)”,“44 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“45 /opt/bitnami/apps/dreamfactory/htdocs/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“46 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(13213): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))”,“47 [internal function]: Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))”,“48 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9963): call_user_func_array(Array, Array)”,“49 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“50 /opt/bitnami/apps/dreamfactory/htdocs/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“51 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(13150): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))”,“52 [internal function]: Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))”,“53 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9963): call_user_func_array(Array, Array)”,“54 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“55 /opt/bitnami/apps/dreamfactory/htdocs/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“56 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(3286): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))”,“57 [internal function]: Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))”,“58 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9963): call_user_func_array(Array, Array)”,“59 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“60 /opt/bitnami/apps/dreamfactory/htdocs/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“61 [internal function]: Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))”,“62 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9948): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“63 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(2366): Illuminate\Pipeline\Pipeline->then(Object(Closure))”,“64 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(2350): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))”,“65 /opt/bitnami/apps/dreamfactory/htdocs/public/index.php(52): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))”,“66 {main}”]}}

There is a table called cart in the kw2-sql-db and the following rest call works from rest client
http://54.202.131.183/api/v2/kw2-sql-db/_table/cart

Also i have create a single all access role from now that allows access from both API and script

Any help would be appreciated

Hi,

instead of calling the endpoint with just the resource path, try to call it with the full url as a workaround. I had a similar problem.

i provide Dissertation Assistance to make a ‘stored procedure’, check your database ‘help’, cause different database have a different structure for Stored Procedure. This Stored Procedure is for INTERBASE (i use interbase) :

Assume the table structure like this :
Create RESTAURANT
(
RestaurantID varchar(10),
OwnerID varchar(10),
RestaurantName varchar(10),
CuisineTypeID varchar(10),
Description varchar(200),
Website varchar(200),
IsListed smallint,
IsFeatured smallint,
views varchar(200)
)

Create CUISINETYPE
(
CuisineTypeID varchar(10),
CuisineName varchar(100)
)

now the Stored procedure :

CREATE PROCEDURE SHOW_RESTAURANT_BY_CUISINENAME
(
vCuisineName varchar(100)
)
RETURNS
(
RestaurantID varchar(10),
OwnerID varchar(10),
RestaurantName varchar(10),
CuisineTypeID varchar(10),
Description varchar(200),
Website varchar(200),
IsListed smallint,
IsFeatured smallint,
views varchar(200)
)
AS
BEGIN
For
Select A.RestaurantID, A.OwnerID, A.RestaurantName,
A.CuisineTypeID, A.Description, A.WebSite, A.IsListed,
A.IsFeatured, A.Views from Restaurant A , CuisineType B
where A.CuisineType=B.CuisineType and B.CuisineName=:vCuisineName
into
RestaurantID, OwnerID, RestaurantName, CuisineTypeID,
Description, WebSite, IsListed, IsFeatured, Views
do
BEGIN
Suspend;
END
END;