7 Replies Latest reply on Jul 3, 2018 9:43 AM by Aryan Anantwar

    Unable to construct JSON request in AO for Update adapter REST call

    Aryan Anantwar

      Hi Experts,

       

      I want to construct the below json using XPATH/XSLT transform editor.

      suppose I have the be low highlighted config xml in a context item called as 'config'.

      So how to generate the below 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"

      }

      ref. Update adapter configuration - Documentation for BMC Atrium Orchestrator Platform 8.0 - BMC Documentation

       

      I did tried with some xslt, but getting error as 'Content is not allowed in prolog'.

      Can someone help me out to build the above json which has a parameter with XML value.

       

      Regards,

      Aryan Anantwar

        • 1. Re: Unable to construct JSON request in AO for Update adapter REST call
          Matthew Highcove

          I think this is what you need:

          772254_XMLinJSON.png

          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

            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 Highcove

              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":"&lt;config&gt;&lt;clear-asynchronous-cache&gt;true&lt;/clear-asynchronous-cache&gt;&lt;delay&gt;30&lt;/delay&gt;&lt;/config&gt;",

                "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

                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.

                ref.Update adapter configuration - Documentation for BMC Atrium Orchestrator Platform 8.0 - BMC Documentation

                 

                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 Highcove

                  Wrapping the entire JSON string in CDATA failed, but wrapping just the adapter configuration succeeded:

                  772254_XMLinJSON_2.png

                  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 Samudrala

                    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.