Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Nested Post Calls in SAP Build Apps

YashminBehera
Explorer
0 Kudos
549

Hi all,

I’ve been working on an interesting use case where I’m creating a product catalog page that allows users to view individual product details pages when selecting a product. As part of this functionality, I’m leveraging a standard service to post data into two entities: A_SalesOrder and A_SalesOrderItem. Here's what I’ve encountered so far and where I need help!

YashminBehera_0-1745242486650.png

 



What I’m Trying to Achieve

  1. Create a Sales Order Record: Populate the header fields (e.g., Sales Order Type, Sales Order, Sales Organization, Distribution Channel, etc.) in the A_SalesOrder entity.

  2. Add Line Items to the Sales Order: Populate the details (e.g., Item Category, Material, Quantity, Price, etc.) in the A_SalesOrderItem entity.

  3. Link Header and Line Items: Ensure that the created SalesOrder is used to associate line items correctly.

    sharing the payload I am following for the post request:

    {
      "d": {
        "SalesOrderType": "OR",
        "SalesOrganization": "1710",
        "DistributionChannel": "10",
        "OrganizationDivision": "00",
        "SoldToParty": "17100100",
        "to_Item": {
          "results": [
            {
              "SalesOrderItem": "000010",
              "SalesOrderItemCategory": "TAN",
              "SalesOrderItemText": "Trad.Good 11,PD,Reg.Trading",
              "Material": "TG11",
              "RequestedQuantity": "10",
              "RequestedQuantityUnit": "PC",
              "NetAmount": "175"

              }
          ]
    }
      }
    }

    I am able to successfully post to the header fields using A_SalesOrder. However, when attempting to post data to the line items (A_SalesOrderItem), I encounter a 400 error (Bad Request) and the post fails.

    YashminBehera_1-1745242537026.png

    this is while I am posting to the header fields.


    YashminBehera_2-1745242613077.png

    while doing the post call to the line items I face this. ( The 941 refers to the salesOrder number while doing the post call to the A_SalesOrder service.)


      • Tried associating the SalesOrder ID with the to_Item nested structure and posting to A_SalesOrderItem using an update record action.

      • Attempted to post to both entities (A_SalesOrder and A_SalesOrderItem) in a single nested post call.

    Despite these efforts, I wasn’t able to achieve the desired result, and the 400 error persisted while posting to the line items.

    YashminBehera_3-1745242811755.pngYashminBehera_4-1745242874072.png

     

    - I’d appreciate guidance on how to make a nested post call that successfully links the A_SalesOrder header and A_SalesOrderItem line items. Specifically:

    1. How to structure the request payload correctly for a nested post.

    2. Whether there are specific settings or configurations required in the service or app variables for associating these entities.

    3. Any example implementations or best practices for handling such scenarios in SAP Build Apps.

    Looking forward to your insights and expertise to resolve this! 😊

     

    @Dan_Wroblewski 
    @eshrinivasan 
    @Joni 

    SAP Build Apps 

 

3 REPLIES 3

Joni
Product and Topic Expert
Product and Topic Expert
0 Kudos
365

Hi @YashminBehera It's not immediately clear from the screenshot what went wrong, except 400 error message, that indicate an issue with one or more parameters — potentially in the URL or the JSON payload of the request.

I’d recommend breaking the request into two parts:

  1. First, try posting the sales order header first.
  2. Once that succeeds, follow up with a separate request to post the sales order item(s).

You can refer to the example parameters (click on example value) for A_Sales_Order below from SAP API Hub:

  1. POST > A_SalesOrder Header
  2. POST > A_SalesOrder('{SalesOrder}')/to_item

You can also test the API call using cURL or Postman to isolate the issue outside of SAP Build Apps. Additionally, inspect the request directly from the SAP Build Apps preview by opening Chrome Developer Tools:

  • Go to the Network tab
  • Filter by Fetch/XHR
  • Review the actual request headers and payload being sent

This should give you better visibility into what's being passed and where the issue might be occurring.
Hope it helps.

0 Kudos
296

Hi @Joni 

Thank you for the reply,

I did try to post headers first and then separately post the sales order item(s), I was able to post the headers but while separately posting the sales order item(s) I receive " Request failed with status code 404".

I tried first with "create record" for sales order item(s) and then I tried the "update record" functionality for sales order item(s), I am unable to post in either of the ways.

Is there any way to post to both headers and the sales order item(s) which is nested in any certain way using sap build apps, can you please guide me in that way.

Regards,
Yashmin Behera

Joni
Product and Topic Expert
Product and Topic Expert
0 Kudos
233

hi @YashminBehera, did you try to troubleshoot with approach given? again I would encourage you to try with postman / curl first. You should be able to post sales order items with the example API link given previously.
Regards.