cancel
Showing results for 
Search instead for 
Did you mean: 

B1i HTTP Post request empty when Payload JSON

JoergAldinger
Active Contributor
0 Kudos

Dear experts:

I have the following HTTP call that actually makes it to the target system but without the payload, eventually returning that a required parameter is missing. If I set the pltype to xml then it does send the payload, but of course it's not understood by the target system. I have also tried text but is also preventing the payload from being sent.

Any idea what I'm missing here to send a JSON POST request with the payload?

Thanks in advance,

Joerg.

Accepted Solutions (1)

Accepted Solutions (1)

bastian_schaefer
Active Contributor
0 Kudos

Hi Joerg,

you can use the tag <query> to handover URL parameters (see extract from HTTP call atom online help):


query id

Enter query strings for your call.

If you want to handover URL parameters containing special characters, you must URL encode the string. The integration framework provides the encode Java function in the utils2 namespace. To ensure that the function works correctly, cast the string with the string XPath function.

Define the call as follows:

<call>

            <xsl:variable name="var">{"myPar":"myVal"}</xsl:variable>

            <query id="json" value="{utils2:encode(string($var))}"/>

            ...

</call>


Conversions from XML towards JSON can be automized by using the specific conversion atom (please compare to online help searching by "JSON"):


In HTTP inbound and outbound, set the payload type to JSON (pltype="jso") or (pltype="json") to receive or hand over a message payload in JSON format. In the inbound phase, the integration framework recognizes the JSON format and converts it to XML. In the outbound phase, the integration framework automatically provides the payload in JSON format.

If you need a JSON representation in the processing phase, use the Conversion XML to JSON atom.

You can find the file with the required schema definition in the BizStore in following place: com.sap.b1i.system/xsd/json_pltype.xsd

You can start with an object using option 1, or with an array, using option 2.

<!-- option 1 - starting in the root with an object-->

<io xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:com.sap.b1i.bizprocessor:bizatoms" pltype="json"

    xsi:schemaLocation="urn:com.sap.b1i.bizprocessor:bizatoms
       json_pltype.xsd">

    <object>

       <!-- optional multiple of the following elements-->

       <string name="">value</string>

       <number name="">value</number>

       <object name="">...</object>

       <array>...</array>

       <bool name="">true/false</bool>

       <null name="" />

    </object>

</io>

<!-- option 2 - starting in the root with an array-->

<io xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:com.sap.b1i.bizprocessor:bizatoms" pltype="jso"

   xsi:schemaLocation="urn:com.sap.b1i.bizprocessor:bizatoms
     json_pltype.xsd">

  <array>

     <!-- optional multiple of the following elements-->

     <string name="">value</string>

     <number name="">value</number>

     <object name="">...</object>

     <array>...</array>

     <bool name="">true/false</bool>

     <null name="" />

    </array>

</io>

Best regards

Bastian

JoergAldinger
Active Contributor
0 Kudos

Hello Bastian:

I had read the information you posted in your reply. But I don't want to hand over URL query parameters, I need to fill the POST body. For two reasons: 1) The Web service expects my payload in the body, not in the URL query. 2) The URL query string is limited to 1024 characters, which may not be enough.

As to the second part of your reply on how to convert to JSON, the JSON conversion is already complete and correct, I have one of those snippets in an earlier atom and they work fine.

The problem really is the POST body going out in blank with no content at all, unless the pltype parameter is set to xml, but then it is including the XML definition and a dummy root tag which messes up the content.

Any more ideas?

Thanks,

Joerg.

bastian_schaefer
Active Contributor
0 Kudos

Hi Joerg,

the explicit maintenance of segment <pltype> "json" is OK.

Problem and trick is that content of the payload tag has to be in XML form, not the JSON form.

It has to be created according to json_pltype.xsd located in /B1iXcellerator/exec/webdav/com.sap.b1i.system/xsd.


After that, you have to also properly configure the htta tag and insert there configuration for HTTP header.

Therefore please additionally maintain httpheader within segment <htta> as follows to make sure the payload is handed over as JSON:


<call>

...

<htta>

<par id="httpheader.???" value="">

<par id="httpheader.Content-Type" value="application/json"></par>

<!--optional - you can specify here your own http header definitions - multiple elements allowed-->

</par>

<par id="htta.returnpltypeforce" value="json">

<!--optional-->

</par>

<par id="htta.returnpltypedefault" value="json">

<!--optional-->

</par>

</htta>

</call>


Best regards

Bastian

JoergAldinger
Active Contributor
0 Kudos

Thank you Bastian, that indeed did the trick. It wasn't clear to me that JSON conversion would happen implicitly when specified in the HTTP call. I had already converted my XML to JSON before so that was the problem.

Thanks again,

Joerg.

Answers (1)

Answers (1)

jan_polak
Participant
0 Kudos

Nice Joerg, Bastian,

maybe this is another solution:

<pltype>json</pltype>

<payload>

  <bfa:io>

    <bfa:object>

      <bfa:array name="Products">

        <bfa:object name="Product">

          <bfa:string name="Title">Title1</bfa:string>

          <bfa:string name="Price">5.0</bfa:string>

        </bfa:object>

        <bfa:object name="Product">

          <bfa:string name="Title">Title2</bfa:string>

          <bfa:string name="Price">6.0</bfa:string>

        </bfa:object>

      </bfa:array>

      <bfa:string name="Customer">Customer</bfa:string>

      <bfa:string name="City">City</bfa:string>

    </bfa:object>

  </bfa:io>

</payload>

<htta>

  <par id="httpheader.Content-Type" value="application/json"/>

  ...

</htta>

Jan