Mashables and Mashups : Mashups in EMML : Advanced Mashup Techniques : Handling JSON Responses or Inputs : Post JSON to a Web Service Using <directinvoke>
Post JSON to a Web Service Using <directinvoke>
For web services that require JSON input parameters, you can use <directinvoke> and the POST method with a variable that has subtype="JSON", such as this example:
...
<variable name="postBody" type="document" subtype="JSON">
<![CDATA[
{"locations": [
{"city":"San Francisco","lat":"37.7668","long":"-122.3959" },
{"city":"Albuquerque","lat":"35.151317","long":"-106.539867"},
{"city":"Seattle","lat":"47.61132","long":"-122.320637"}
]}
]]>
</variable>

<directinvoke endpoint="http://someOrg.com/jsonService" method="POST"
requestbody="$postBody" outputvariable="svcResponse"/>
...
In this example, the JSON is defined directly in the variable, but you can also use <assign> or <constructor> to assemble or build a JSON object.
You can also set the datatype for the response from the web service to JSON, simply by declaring the datatype and subtype of the variable to receive the response:
...
<variable name="postBody" type="document" subtype="JSON">
<![CDATA[
{"locations": [
{"city":"San Francisco","lat":"37.7668","long":"-122.3959" },
{"city":"Albuquerque","lat":"35.151317","long":"-106.539867"},
{"city":"Seattle","lat":"47.61132","long":"-122.320637"}
]}
]]>
</variable>
<variable name="svcResponse" type="document" subtype="JSON"/>

<directinvoke endpoint="http://someOrg.com/jsonService" method="POST"
requestbody="$postBody" outputvariable="svcResponse"/>
...
Copyright © 2013-2016 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback