Problem with createRecord()


#1

Hi

I am exploring the option of using dreamfactory for some APIs that I want to publish .
I have created a service with connection to a mysql DB hosted on AWS and can see API docs auto generated. The GET methods are working fine and I can retrieve records from the table.
For a simple table with some fields related to user details, I am trying to create a DB entry using the POST method for function “createRecord()”. I am getting the following error

>  {
>   "error": {
>     "context": null,
>     "message": "Create record by identifier not currently supported.",
>     "code": 400,
>     "trace": [
>       "0 [internal function]: DreamFactory\\Core\\Resources\\BaseDbTableResource->handlePost()",
>       "1 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Components/RestHandler.php(271): call_user_func(Array)",
>       "2 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Components/RestHandler.php(177): DreamFactory\\Core\\Components\\RestHandler->processRequest()",
>       "3 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Components/RestHandler.php(224): DreamFactory\\Core\\Components\\RestHandler->handleRequest(Object(DreamFactory\\Core\\Utility\\ServiceRequest), 'ig_user/438')",
>       "4 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Services/BaseDbService.php(116): DreamFactory\\Core\\Components\\RestHandler->handleResource(Array)",
>       "5 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Components/RestHandler.php(172): DreamFactory\\Core\\Services\\BaseDbService->handleResource(Array)",
>       "6 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Services/BaseRestService.php(65): DreamFactory\\Core\\Components\\RestHandler->handleRequest(Object(DreamFactory\\Core\\Utility\\ServiceRequest), '_table/ig_user/...')",
>       "7 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Utility/ServiceHandler.php(57): DreamFactory\\Core\\Services\\BaseRestService->handleRequest(Object(DreamFactory\\Core\\Utility\\ServiceRequest), '_table/ig_user/...')",
>       "8 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(17493): DreamFactory\\Core\\Utility\\ServiceHandler::processRequest('v2', 'instagoapp', '_table/ig_user/...')",
>       "9 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(17469): DreamFactory\\Http\\Controllers\\RestController->handleService('v2', 'instagoApp', '_table/ig_user/...')",
>       "10 [internal function]: DreamFactory\\Http\\Controllers\\RestController->handlePOST('v2', 'instagoApp', '_table/ig_user/...')",
>       "11 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8766): call_user_func_array(Array, Array)",
>       "12 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8835): Illuminate\\Routing\\Controller->callAction('handlePOST', Array)",
>       "13 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8815): Illuminate\\Routing\\ControllerDispatcher->call(Object(DreamFactory\\Http\\Controllers\\RestController), Object(Illuminate\\Routing\\Route), 'handlePOST')",
>       "14 [internal function]: Illuminate\\Routing\\ControllerDispatcher->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))",
>       "15 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9472): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))",
>       "16 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(17857): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))",
>       "17 [internal function]: Dreamfactory\\Http\\Middleware\\Limits->handle(Object(Illuminate\\Http\\Request), Object(Closure))",
>       "18 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9464): call_user_func_array(Array, Array)",
>       "19 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(17752): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))",
>       "20 [internal function]: DreamFactory\\Http\\Middleware\\AccessCheck->handle(Object(Illuminate\\Http\\Request), Object(Closure))",
>       "21 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9464): call_user_func_array(Array, Array)",
>       "22 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))",
>       "23 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9454): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))",
>       "24 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8816): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))",
>       "25 /opt/bitnami/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), 'handlePOST')",
>       "26 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7755): Illuminate\\Routing\\ControllerDispatcher->dispatch(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request), 'DreamFactory\\\\Ht...', 'handlePOST')",
>       "27 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7726): Illuminate\\Routing\\Route->runWithCustomDispatcher(Object(Illuminate\\Http\\Request))",
>       "28 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7379): Illuminate\\Routing\\Route->run(Object(Illuminate\\Http\\Request))",
>       "29 [internal function]: Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))",
>       "30 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9472): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))",
>       "31 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))",
>       "32 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9454): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))",
>       "33 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7380): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))",
>       "34 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7368): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request))",
>       "35 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7353): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request))",
>       "36 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(2262): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request))",
>       "37 [internal function]: Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request))",
>       "38 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9472): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))",
>       "39 /opt/bitnami/apps/dreamfactory/htdocs/vendor/barryvdh/laravel-cors/src/HandleCors.php(43): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))",
>       "40 [internal function]: Barryvdh\\Cors\\HandleCors->handle(Object(Illuminate\\Http\\Request), Object(Closure))",
>       "41 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9464): call_user_func_array(Array, Array)",
>       "42 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(17836): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))",
>       "43 [internal function]: DreamFactory\\Http\\Middleware\\FirstUserCheck->handle(Object(Illuminate\\Http\\Request), Object(Closure))",
>       "44 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9464): call_user_func_array(Array, Array)",
>       "45 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(12789): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))",
>       "46 [internal function]: Illuminate\\View\\Middleware\\ShareErrorsFromSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))",
>       "47 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9464): call_user_func_array(Array, Array)",
>       "48 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(11412): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))",
>       "49 [internal function]: Illuminate\\Session\\Middleware\\StartSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))",
>       "50 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9464): call_user_func_array(Array, Array)",
>       "51 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(12530): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))",
>       "52 [internal function]: Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse->handle(Object(Illuminate\\Http\\Request), Object(Closure))",
>       "53 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9464): call_user_func_array(Array, Array)",
>       "54 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(12469): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))",
>       "55 [internal function]: Illuminate\\Cookie\\Middleware\\EncryptCookies->handle(Object(Illuminate\\Http\\Request), Object(Closure))",
>       "56 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9464): call_user_func_array(Array, Array)",
>       "57 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(2936): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))",
>       "58 [internal function]: Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle(Object(Illuminate\\Http\\Request), Object(Closure))",
>       "59 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9464): call_user_func_array(Array, Array)",
>       "60 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))",
>       "61 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9454): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))",
>       "62 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(2209): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))",
>       "63 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(2192): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))",
>       "64 /opt/bitnami/apps/dreamfactory/htdocs/public/index.php(53): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))",
>       "65 {main}"
>     ]
>   }
> }

I passed following parameters in the call

{
  "id": 1,
  "userid": 1,
  "user_fname":"A" ,
  "user_lname": "M",
  "user_email": "A@B.COM",
  "user_age": 32  ,
  "user_gender": ,
  "user_dob" : ,
   "user_dp_id" : 
}

and

id = 201

The API end point looks like

http://xyz.abc.com:80/api/v2/dbName/_table/ig_user/201

Any advise or pointers on how to get this sorted ?


#2

You should just use create record instead of create record by id.
In which case, you endpoint would be

http://xyz.abc.com:80/api/v2/dbName/_table/ig_user

You can specify the ID in the json object, or if you use autoincrmenting ids, you can leave it out altogether.


#3

Hey @drewpearce

Thanks for your response , I tried the createRecords() . It ends with response code 200 , but no rows are created in the table.

>  http://xyz.abc.com:80/api/v2/dbName/_table/ig_user_logins?id_field=userId&id_type=string&continue=true&rollback=false&fields=userId

The parameters passed are as below

> {
>   "record": [
>     {
>       "userId": 3,
>       "marketId": "IND",
>       "loginId": "testUser3",
>       "loginMode": "iG",
>       "loginPass": "sadf83rmxm!234",
>       "lastLoginDate": "2015-10-30",
>       "accountLockedInd": "N",
>       "lastAttemptedDate": "2015-10-30",
>       "prevPass1": null,
>       "prevPass2": null,
>       "prevPass3": null,
>       "prevPass4": null,
>       "prevPass5": null
>     },
>     {
>       "userId": 4,
>       "marketId": "IND",
>       "loginId": "testUser4",
>       "loginMode": "iG",
>       "loginPass": "Axdfsskj834549!dsf8dfj30!@",
>       "lastLoginDate": "2015-10-27",
>       "accountLockedInd": "N",
>       "lastAttemptedDate": "2015-10-27",
>       "prevPass1": "34rfaaaOPERMLAkmcaaopm",
>       "prevPass2": null,
>       "prevPass3": null,
>       "prevPass4": null,
>       "prevPass5": null
>     }
>   ]
> }

Response Body:

{
  "resource": [
    {
      "userId": 1
    },
    {
      "userId": 2
    }
  ]
} 

Response Code

200

Can you help please ? Why are no entries created even if the API Returns success


#4

The API is treating your call as a GET. Note the userIds returned are not the ones you POSTed. Do you have the latest version? If not, and you’re using API Docs, the verb may be forced to GET due to an issue that’s now fixed. I recommend using an external client or updating your code.

You are also likely confusing the API with the "record" wrapper. I recommend using the standard "resource" as record was deprecated with 1.x.


#5

Thanks @jeffreystables . Worked for me after user createRecords and trying from Paw. I also change record to resource in the body.

Cheers
Abhijit