Testing via Curl and getting No records detected in request error 400

Im testing the following curl statement in order to POST into a particular table:

curl -H “X-DreamFactory-Application-Name: UAT” -X POST http://localhost/rest/UAT/CRM_LEAD
-d ‘{“STEP_CODE”:“ENQ”,“DOC_GUID”:“10000”,“DOC_DATE”:“2014-07-24”,“DOC_REF”:“WEB_SUBMISSION”,“ORIGINATOR”:“ADMIN”}’

but every time that I try it I get back the error “No record(s) detected in request”.

Any ideas?
I’d also like to just use the REST API without having to specify the Application, since all I want to be able to do is POST some data into one of the services that I have created. Is that possible?

Have a look at this cURL PATCH request - and see if you can PATCH a record simply for testing purposes:

Update todo with id = 1 -----> be sure to append the 1 to cURL

curl -k -3 -X PATCH https://dsp-yourdsp.cloud.dreamfactory.com/rest/db/todo/1 \
  -H "X-DreamFactory-Application-Name: app_name here" \
  -H "X-DreamFactory-Session-Token: session token here" \
  -d '{ "name" : "success"}'

If you notice the rest/db(service)/todo(table)/1(record)

So, this will clearly update record one’s complete name field to: success

note: change the values to match what’s in your todo DB, but only try to update one value.


POSTing a record doesn’t require any id params, as it should update the id (most likely the primary key) by one.

curl -k -3 -X POST https://dsp-yourdsp.cloud.dreamfactory.com/rest/db/todo
-H “X-DreamFactory-Application-Name: app name here”
-H “X-DreamFactory-Session-Token: token here”
-d ‘{ “name” : “curl todo”, “complete” : false }’


As far as your question about updating the db without having an actual app_name in the request. You can preview how to do this with your Live API - simple go to the db service, and create records using valid JSON and it’ll become clear very quick how it’s done.

You’ve probably seen this but if not, have a look:

https://github.com/dreamfactorysoftware/dsp-core/wiki/Common-Headers-Parameters

https://github.com/dreamfactorysoftware/dsp-core/wiki/cURL-Examples

Let me know if you’ve got anymore questions.

Thanks,

  • Mark

Hi Mark,

I have been trying to get this to work, but I just cant seem to get any record to PATCH or to POST.

I cant figure out how to get a successful GET even.

What settings do I need to make in an application in order to connect it to a Service?

Or am I wrong? I dont need a service to access a db from a REST URL and I am approaching this in the wrong fashion?

Hey Nick, what database are you trying to access? You need to have a service set up in DreamFactory to call it with REST. There’s a default service called /db which is provided for you in the DSP and returns data from the default MySQL database. Or you can add your own database as a service.

See these cURL examples for the todo table in /db. There are some screencast examples too which demonstrate API calls with cURL. Remember to pass in an app ID and session token to the API call, like below (get the session token from a login POST to /user/session). As a DSP admin you will automatically have access to the /db service. If you set up other roles, you need to grant /db API access to the role (CRUD permissions).

curl -k -3 -X GET https://dsp-yourdsp.cloud.dreamfactory.com/rest/db/todo \
  -H "X-DreamFactory-Application-Name: todojquery" \
  -H "X-DreamFactory-Session-Token: bhc7lov8r41h4cbn6pue1r63gbgh7jf6"
1 Like

Hi Ben,

Let me just run through this,

I’ve set-up a service called UAT which connects to a SQL Database (The Swagger API works nicely). In this DB there is a table called CRM_LEAD that I wish to see if I can POST entries into from a web service.

I’ve enabled CORS with a * value for the moment, and I have enabled Guest User with the Role UAT-ROLE which is enabled for CRUD operations on the service UAT. So I shouldnt need a session ID from what I understand.

With regard to the App ID, I havent really built an app as all I want to experiment with is the REST service directly. Could you recommend how I should set-up the App so that I can simply write files into this DB?

Thank you

Got it. So you do need to pass app name, but it’s trivial to set up. In the Apps tab of the DSP admin console, just create a new app and use the name of the app as the app ID (i.e. API key) in your REST calls. Note that the REST service you created does not need to know anything about this app…apps and services are completely decoupled.

There’s more info on API key here. If you’re still having issues, you might want to email support@dreamfactory.com so we can help get your calls sorted out.

Hi Ben,

Ok, I’ve tried that now, but I am getting another error stating “No record(s) detected in request.”

Ill email through to support though, Im using the following curl request.

curl -k -3 -X POST http://LOCALHOST/rest/UAT/CRM_LEAD -H “X-DreamFactory-Application-Name: UAT_APP” -d ‘{“PROCESS_CODE”:“PROPERTYSALES”,“STEP_CODE”:“ENQ”,“DOC_GUID”:“10000”,“DOC_DATE”:“2014-07-24”,“DOC_REF”:“WEB_SUBMISSION”,“ORIGINATOR”:“ADMIN”,“LEAD_STATUS”:“A”,“LEAD_CURRENCY”:“£”,“SALUTATION”:“Mr”,“L_NAME”:“cunhatest10”,“F_NAME”:“hugotest10”,“COUNTRY_CODE”:“UK”,“EMAIL”:“hugo.cunha10@jellyfish.co.uk”,“GENERAL_INTEREST”:"",“SOURCE_CODE”:“TOBEQUALIFIED”,“COMPLETION_STATUS”:“D”,“APPROVAL_STATUS”:“N”,“TEL_3”:“345345111”,“CNT_MEHOD_CODE”:“INTERNET-ENQUIRY”,“DECLINE_USE”:“Y”}’

Nick,

First, open browser and turn on debugger. Go to your live api on the admin console, scroll through the services and open the sql server (which would be UAT from your curl request) - and perform a GET. Basic, top-level, GET.

What was the response and the request URL (within swagger, the live api).

Now… perform a POST against your MSSQL server using the exact data that you’re trying to POST via cURL - which will accomplish the same thing, but that’s not the reason I’m asking you to do it.

After you do this, look at the request URL and let me know what it is, via forum or respond to the email I just replied to. Now, go into the debugger and look for the REQUEST and RESPONSE information… In chrome or firefox (think u need firebug installed for FF).

But, yeah it should be as simple as what you already have.

curl -k -3 -X POST http://localhost/rest/UAT/CRM_LEAD \
  -H "X-DreamFactory-Application-Name: UAT_APP" \
  -d '{ "name" : "game", "complete" : false }'

Thanks,

Mark

Hi Mark,

The response from the top level get was a response body that listed all of the tables and then all of the permissions applicable.

The request URL was:

http://localhost:80/rest/UAT

When I then POST to CRM_LEAD using the Swagger API it takes ages to perform the action (a good few minutes) and then came back with no content to the URL
http://localhost:80/rest/UAT/CRM_LEAD

I ran it a second time to be sure and then within a few seconds it had returned with a correct

{
“DOC_GUID”: “10000”
}

and now I can see my data in the back-end.

Ill see if I can find the REQUEST RESPONSE information

Nick

So, it is working for you now, there’s now a performance issue?

No worries on the request/response if all is good for you - continue to run a few tests to see if performance is still giving you difficulty and we’ll go from there.

Thanks,

  • Mark

I can get it to work from swagger, but I cant get it work from curl, which is what I really need to demonstrate. The same data is used and everything that I can think of but I get an error where it seems to think that the data sections are tables it should be looking up.

I cant find the request/response in the debug information either as Im not too familiar with the tool. Im using Chrome but I may take a look at Firebug.

Which OS are you using again? I think it is Windows… In which case, some users I’ve noticed have to use double quotes and escape characters for -d value. It is worth a shot at this point, I’d say.

[This image is no longer available]

Try the one that has 28 next to it - this should address your issue.

Give that a try and if doesn’t work then take a look at this on StackOverflow, as it has a few other potential solutions.

Thanks,

  • Mark

Right, this seems to be the solution here:

http://stackoverflow.com/questions/11834238/curl-post-command-line-on-windows-restful-service

Effectively, under windows command line, cURL messes up the JSON formatting. I tested now using the Advanced Rest Client tool and also with curl under cygwin and it works properly. Apologies for the confusion but its a good one to note for others.

Thank you for all your help.

N

1 Like

Great man! Awesome work.

Thanks,

  • Mark