-
1. Re: Unable to construct JSON request in AO for Update adapter REST call
Matthew HighcoveJun 28, 2018 12:41 PM (in response to Aryan Anantwar)
I think this is what you need:
The XSLT Transform Editor is intended to take XML inputs and return XML outputs. Using it to accept and output JSON is tricky and requires wrapping the JSON string in a root XML element (here, <JSON>). This transform gets everything before "configuration", rebuilds "configuration" with a token containing your XML, and finishes with everything after the double quotes after "configuration".
Please note that the substring functions wrap their parameters in single quotes so they can look for double quotes, and this transform assumes you have an empty "configuration" tag in your JSON input. The same principle should work for any element but this exact transform expects "configuration".
-
2. Re: Unable to construct JSON request in AO for Update adapter REST call
Aryan Anantwar Jun 29, 2018 3:33 AM (in response to Matthew Highcove)Hi Matthew,
Thanks for your response.
I am already able to generate the kind of result you shown in above screenshot.
The problem is the output has a XML root node (in your sample it's <JSON>), and i need the only the JSON content within it.
Which i need to pass to another workflow/call.
I tried using xpath as //JSON/*, //JSON/text(), String(//JSON) but none of these produced the expected output.
<JSON>
{
"name": "WebServiceAdapterNew",
"description":"New adapter configuration",
"adapterType": "ro-adapter-ws",
"version":"20.16.02.00",
"revision": "1",
"configuration":"<config><clear-asynchronous-cache>true</clear-asynchronous-cache><delay>30</delay></config>",
"configurationDataType":"xml"
}
</JSON>
expected:
{
"name": "WebServiceAdapterNew",
"description":"New adapter configuration",
"adapterType": "ro-adapter-ws",
"version":"20.16.02.00",
"revision": "1",
"configuration":"<config><clear-asynchronous-cache>true</clear-asynchronous-cache><delay>30</delay></config>",
"configurationDataType":"xml"
}
Regards,
Aryan Anantwar
-
3. Re: Unable to construct JSON request in AO for Update adapter REST call
Matthew HighcoveJun 29, 2018 6:52 AM (in response to Aryan Anantwar)
BAO does not use strings. On the backend context items that contain strings actually contain an XML document with a single node. Even context items with the value "true" are actually "<value>true</value>" in BAO's memory. This means what you need is XML that contains a string that contains XML, for which BAO should interpret the root XML elements but treat everything else, including all further XML elements, as a string.
The closest I've been able to get is wrapping the JSON string in CDATA tags:<JSON><![CDATA[
{
"name": "WebServiceAdapterNew",
"description":"New adapter configuration",
"adapterType": "ro-adapter-ws",
"version":"20.16.02.00",
"revision": "1",
"configuration":"<config><clear-asynchronous-cache>true</clear-asynchronous-cache><delay>30</delay></config>",
"configurationDataType":"xml"
}]]>
</JSON>
The transform string(//JSON) then gives me this:
<result>
{
"name": "WebServiceAdapterNew",
"description":"New adapter configuration",
"adapterType": "ro-adapter-ws",
"version":"20.16.02.00",
"revision": "1",
"configuration":"<config><clear-asynchronous-cache>true</clear-asynchronous-cache><delay>30</delay></config>",
"configurationDataType":"xml"
}
</result>
I don't know what your use case is so I can't test whether this will work for you.
-
4. Re: Unable to construct JSON request in AO for Update adapter REST call
Aryan Anantwar Jun 29, 2018 7:09 AM (in response to Matthew Highcove)Hi Matthew,
Thanks for your efforts find the solution for my issue.
I am trying to build the JSON request for BAO REST API to Update Adapter configuration.
Where it need a JSON with one parameter contains XML as value.
Regards,
Aryan Anantwar
-
5. Re: Unable to construct JSON request in AO for Update adapter REST call
Matthew HighcoveJun 29, 2018 10:13 AM (in response to Aryan Anantwar)
Wrapping the entire JSON string in CDATA failed, but wrapping just the adapter configuration succeeded:
This transform outputs me a correct-looking XML document. I passed this to :AutoPilot-AD-Utilities:REST:Put with the XPath transform /JSON/text(). The adapter understood the request and passed it to BAO's REST API, and BAO updated the adapter configuration.
-
6. Re: Unable to construct JSON request in AO for Update adapter REST call
Ranganath SamudralaJun 29, 2018 1:49 PM (in response to Matthew Highcove)
Use the workflow "Convert Input Parameters XML to JSON" in the latest 20.18.01 version of AutoPilot-OA-Common_Utilities in the folder AutoPilot-OA-Common_Utilities:BAO_Utilities:REST.
-
7. Re: Unable to construct JSON request in AO for Update adapter REST call
Aryan Anantwar Jul 3, 2018 9:43 AM (in response to Matthew Highcove)Thanks Matthew, it worked like a charm.