How to create a DSP service which make a remote web service POST call with parameters?

Hi

I am stuck in a scenario, where I need to create a remote web service in DSP which makes a POST call to actual web service.

My issues:.
In DSP config what is base url( BaseURL )???
In swagger json, what are the values of ‘host’, ‘basePath’ and ‘schemes’ ?

I short, I need to access a remote web service:
POST https://abc.def.com/info
with a payload:
“token” : “gfhiasgertttyy”

And I need a dsp service for the above call as shown below:
POST http://mydspinstance.com:8080/api/v2/auth/info
with a payload:
“token” : “gfhiasgertttyy”

How can I accomplish this?

@abhinavg first I would recommend reading DreamFactory guide to HTTP services.

The base URL for your service really depends on the service itself, typically I use the minimal URL required to use API. As an example lets take a look at NASA API.

The base URL is: api.nasa.gov/planetary/apod

And the example query shown: api.nasa.gov/planetary/apod?api_key=DEMO_KEY

The ‘?’ shown starts the query as shown the parameter here is ‘api_key’.

The ‘api_key’ parameter is configurable inside DreamFactory as described in the DreamFactory docs.

For creating your Swagger I’ve found the easiest process to be testing the API using a REST client like Postman then saving my successful REST API calls to Postman collections then having this handy tool transform the collection in to Swagger for me. It may require some minimal tweaking to work inside DreamFactory but is much simpler then building from scratch. Hope this helps!

1 Like

@abhinavg also the example URLs I provided above typically have https:// in front of them but forum wouldn’t allow me to place more than two links in my post as I’m new user.

Thanks Sasquatch. I will lookout apimatic. I have already read dreamfactory wiki and tutorials on adding a web service, but I couldn’t find an example to do a POST call. After the setting mentioned in dreamfactory docs when I tried to do POST on my newly created dreamfactory service(which in turn would do a POST request to external web service) using curl, I get the below error:
{"error":{"context":null,"message":"Undefined offset: 1","code":500, "trace":["..."] }

Also I cant get how to pass POST body to external web service ??
Here are the relevant screenshots.

@abhinavg This was a bug in earlier versions from what I can read on the internets. You might consider updating and testing again.

Well, I am using dreamfactory-2.3.0-4. It is the latest version. Hopefully someone can confirm that is it a bug in this version.

Here is my curl request:

curl -i -X POST --data “token=eyJ0eXAiOiJKI1NiJ9.eyJlbWFpbCIwNDJ9.gfzyPfJG9DCg” “http://mydspinstance.com:8080/api/v2/auth/info” -H “X-DreamFactory-Api-Key: 4755…5cfbd2”

This should do:
POST https://abc.def.com/info

successfully giving the response in JSON.
BUT it is not doing so. Anyone?

@abhinavg you are not using latest. See release notes: https://wiki.dreamfactory.com/DreamFactory/Release_Notes#Version_2.3.1_.28Released_October_4.2C_2016.29

@abhinavg you are not on the latest version @Sasquatch is correct updating to the latest 2.3.1 release resolves this.

2 Likes

Yep, I will try that and revert tomorrow.

With a fresh local bitnami install of 2.3.1 release, I tested POST request; and it is working fine so far. Thanks to @Sasquatch and @mattschaer.

BUT the GET request is not working on 2.3.1.

My curl request:
curl -i -k -3 -X GET “http://mydspinstance.com:8080/api/v2/auth/userinfo” -H “X-DreamFactory-Api-Key: 475…fbd2” -H “Content-Type: application/json” -H "Authorization: Bearer R35…gP"

This should do:
GET https://abc.def.com/userinfo

BUT the output is:

HTTP/1.1 400 Bad Request
Date: Sun, 23 Oct 2016 05:02:27 GMT
Server: Apache
X-Frame-Options: SAMEORIGIN
Vary: Cookie
X-Powered-By: PHP/7.0.11
Cache-Control: no-cache
Content-Length: 89
Connection: close
Content-Type: application/json

{“error”:{“context”:null,“message”:“Invalid token: Wrong number of segments”,“code”:401}}

Any clues ?

Relevant screenshot:

Marking this thread as solved, and created new thread for GET request with Authorization Bearer header here.

Thanks.

1 Like