cancel
Showing results for 
Search instead for 
Did you mean: 

"How to Correctly Convert JSON to XML for OData v2 Adapter in SAP CPI for S/4HANA SaleOrder API Req"

satheshM
Explorer
0 Kudos
267

I am working on an integration scenario in SAP CPI where I need to call the S/4HANA System A_SalesOrder API. The API works perfectly fine with JSON payload when tested in Postman. However, when implementing this integration using the OData v2 adapter in CPI with the same JSON request payload, I encounter the following error:

"An internal server error occurred: Request Payload Parsing Failed. Possible reasons include: (1) The OData metadata content available on the server might be outdated, or (2) The request payload seems to be incorrect. Error Details: only whitespace content allowed before start tag and not { (position: START_DOCUMENT seen {... @1:1), org.xmlpull.v1.XmlPullParserException: only whitespace content allowed before start tag and not { (position: START_DOCUMENT seen {... @1:1)."

In an attempt to resolve this, I converted the JSON payload to XML and sent it, but now I receive a different error:

"An internal server error occurred: Request Payload Parsing Failed. Possible reasons include: (1) The OData metadata content available on the server might be outdated, or (2) The request payload seems to be incorrect. Error Details: Parsing exception for XML node <Material>, com.sap.gateway.core.ip.processor.exception.ODataProcessingException: The XML is malformed at node <Material>."

I have found a blog that discusses converting JSON to XML for this purpose: Posting Sales Orders into S/4HANA Cloud API - Part 2. However, I am unsure about the exact XML structure needed. Can someone provide detailed guidance on how to correctly convert JSON to XML for this scenario and ensure it meets the requirements of the OData v2 adapter?

 

satheshM_0-1722915771956.png

when I tried from postman it is working 

satheshM_1-1722915888005.png

but I tried from cpi useing json getting error

req payload :

{
    "SalesOrderType": "OR",
    "SalesOrganization": "MBSO",
    "DistributionChannel": "MC",
    "OrganizationDivision": "MD",
    "SoldToParty": "3200000043",
    "PurchaseOrderByCustomer": "alk",
    "TransactionCurrency": "INR",
    "to_Item": {
        "results": [
            {
                "SalesOrderItem": "10",
                "Material": "81",
                "RequestedQuantity": "10",
                "ProductionPlant": "MBP1",
                "to_ScheduleLine": {
                    "results": [
                        {
                            "ScheduleLine": "1",
                            "ScheduleLineOrderQuantity": "10"
                        }
                    ]
                },
                "to_PricingElement": {
                    "results": [
                        {
                            "ConditionType": "PRMB",
                            "ConditionCurrency": "INR",
                            "ConditionQuantity": "10",
                            "ConditionRateValue": "150.0000"
                        }
                    ]
                }
            }
        ]
    },
    "to_Partner": {
        "results": [
            {
                "PartnerFunction": "SP",
                "Customer": "3200000006"
            },
            {
                "PartnerFunction": "BP",
                "Customer": "3200000006"
            }
        ]
    }
}
 
error:satheshM_2-1722916043008.png

 

so I have converted to xml still getting some error like :

satheshM_3-1722916147900.png

 

so I found one blog this one :#https://community.sap.com/t5/enterprise-resource-planning-blogs-by-sap/posting-sales-orders-into-s-4...

so in this blog I found request xml mapping like this 

satheshM_4-1722916246865.png

I changed the xml structure accrodingly so my structure look like this 

<A_SalesOrder>
    <A_SalesOrderType>
        <SalesOrderType>OR</SalesOrderType>
        <SalesOrganization>MBSO</SalesOrganization>
        <DistributionChannel>MC</DistributionChannel>
        <OrganizationDivision>MD</OrganizationDivision>
        <SoldToParty>3200000043</SoldToParty>
        <PurchaseOrderByCustomer>AleranT</PurchaseOrderByCustomer>
        <TransactionCurrency>INR</TransactionCurrency>
        <to_Item>
            <A_SalesOrderItemType>
                <SalesOrderItem>10</SalesOrderItem>
                <Material>81</Material>
                <RequestedQuantity>10</RequestedQuantity>
                <ProductionPlant>MBP1</ProductionPlant>
                <to_ScheduleLine>
                    <results>
                        <ScheduleLine>1</ScheduleLine>
                        <RequestedQuantity>10</RequestedQuantity>
                    </results>
                </to_ScheduleLine>
                <to_PricingElement>
                    <results>
                        <ConditionType>PRMB</ConditionType>
                        <ConditionCurrency>INR</ConditionCurrency>
                        <ConditionQuantity>10</ConditionQuantity>
                        <ConditionRateValue>150.0000</ConditionRateValue>
                    </results>
                </to_PricingElement>
            </A_SalesOrderItemType>
        </to_Item>
        <to_Partner>
            <results>
                <PartnerFunction>SP</PartnerFunction>
                <Customer>3200000006</Customer>
            </results>
            <results>
                <PartnerFunction>BP</PartnerFunction>
                <Customer>3200000006</Customer>
            </results>
        </to_Partner>
    </A_SalesOrderType>
</A_SalesOrder>
 
but still getting node parsing error because of some field like 
  <ConditionCurrency>INR</ConditionCurrency>
                        <ConditionQuantity>10</ConditionQuantity>
                        <ConditionRateValue>150.0000</ConditionRateValue
but in that blog I cant see the proper xml fieldname for this three so I simple removed and tried. so my structure look like this 
 
<A_SalesOrder>
    <A_SalesOrderType>
        <SalesOrderType>OR</SalesOrderType>
        <SalesOrganization>MBSO</SalesOrganization>
        <DistributionChannel>MC</DistributionChannel>
        <OrganizationDivision>MD</OrganizationDivision>
        <SoldToParty>3200000043</SoldToParty>
        <PurchaseOrderByCustomer>AleranT</PurchaseOrderByCustomer>
        <TransactionCurrency>INR</TransactionCurrency>
        <to_Item>
            <A_SalesOrderItemType>
                <SalesOrderItem>10</SalesOrderItem>
                <Material>81</Material>
                <RequestedQuantity>10</RequestedQuantity>
                <ProductionPlant>MBP1</ProductionPlant>
                <to_ScheduleLine>
                    <results>
                        <ScheduleLine>1</ScheduleLine>
                        <RequestedQuantity>10</RequestedQuantity>
                    </results>
                </to_ScheduleLine>
                <to_PricingElement>
                    <results>
                        <ConditionType>PRMB</ConditionType>
                       
                    </results>
                </to_PricingElement>
            </A_SalesOrderItemType>
        </to_Item>
        <to_Partner>
            <results>
                <PartnerFunction>SP</PartnerFunction>
                <Customer>3200000006</Customer>
            </results>
            <results>
                <PartnerFunction>BP</PartnerFunction>
                <Customer>3200000006</Customer>
            </results>
        </to_Partner>
    </A_SalesOrderType>
</A_SalesOrder>  
 
 
so useing this structure to I can able to create sale order Sucessfully but still I need those three fields   <ConditionCurrency>INR</ConditionCurrency>
                        <ConditionQuantity>10</ConditionQuantity>
                        <ConditionRateValue>150.0000</ConditionRateValue>
 
so how to find out the proper xml request format   plz anyone help me to find out this Thank you
 
View Entire Topic
PRAGSMATIC
Participant
0 Kudos

Are you using ODATA Adapter or REST Adapter to connect to Odata API ?

 

dineshhome1361_7
Participant
0 Kudos

is the parsing error you are receiving is while posting the data to s4? have you tried using string for the 3 fields you have highlighted??