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?
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:
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).
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?
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.
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.
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
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.
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.
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.