Making HTTP calls with JSON content

I need to consume a REST service from Integration Server.

I currently do it is as follows:

  • Populate the content of the request in an IS document
  • Use pub.json:documentToJSONString to convert an IS document to a JSON representation
  • Use pub.client:http to make an HTTP request. The json string from the previous step is mapped to data/string. In order to have the right headers, I added content-type and Accept along with values to the headers input.

Is this the best way to do it in the current version (9.7)? Is it the only way?

Thanks.

Hi Juanal, Can you please let me know how did you implement this. I have similar requirement. Can you reply at your earliest.

Many Thanks!

Hi Kumar

I’ve just created a blog entry that details this process here:

I’m interested to know whether you find it useful.

Regards

Juanal.

1 Like

Hello Juanal,

Intresting article. Thank you.

It’s indeed useful Juanal…thanks for sharing in this forum!

Is this the best way to do it in the current version (9.7)? Is it the only way?<<<

It is indeed the way to do it if you are communicating with a non-IS server.

If you’re talking to another IS, you can use the (new in 9.7) com.wm.app.b2b.client.JSONClient. This class is very similar to com.wm.app.b2b.client.Context, which you may be familiar with, but it transmits JSON payloads rather than binary-encoded or xml-encoded IData.

Regards,
Michael

Nice tutorial!

Another scenario would be to send to the REST endpoint also an attachment.

Have you tried this?

Does it work?

Vlad Turian

Dears,

Please find the snapshots to implement HTTP using JSON Request Call.
For pushing request use REST Client.

Note:While making setResponse2 hardcode Content-Type=‘application/json’.



Dear Experts,

I got a requirement like, My client will send JSON data(Inbound JSON data) and we need to validate and send response if it is valid data if it is not valid we need to send an error email.

Could you please let me know,

  1. How to validate JSON data since we don not have built-in service to validate the JSON data (like we have built in services for flat and xml files)
  2. Could you please let me know the services to send response (Is it pub.flow.setResponse or pub.client.http )

Many thanks for your valuable inputs

  1. Create a Document type on IS against which you want to validate the JSON.
  2. Convert the inbound JSON to document using pub.json:jsonStringToDocument or pub.json:jsonStreamToDocument what ever is relevant.
  3. Use pub.schema:validate and map your output document from Step-2 to “object” and set “conformsTo” as the document type you created in Step-1

Regarding response, if your source is calling via some javascript and set the HTTP header “Accept” or “Content-type” to “application/json” then you need not do anything from your side on IS. The response will go just fine. But it is better to use pub.flow:setResponseHeader and set “fieldName” as “content-type”, “fieldValue” as “application/jsonN”. Whatever is the output of your flow service will now go as JSON to the source.