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.