Array data in Body of single HTTP Request

Hi, I’ve built my Workflow (great tool BTW) and got my JSON data formatted and merged ready to use successfully but now need to use this array data in a single HTTP Request with all the JSON data in the Body of the request.

The HTTP Request seems to either call for each item in the array or if I switch to execute once only does the first item (which sort of makes sense given the issue).

I’m new to the product so I assume I’m just missing something??

Thanks

Hi @jasonR :wave: Welcome to the community :tada:

Can you share your workflow and the JSON of the data you’re working with so we can take a closer look into this for you?

Hi,

Thanks for helping…

For context, I’m sending an update to a Sales Order in an ERP (that is coming from an excel file) and the API expects all line updates to the SO to be in the Body of the API call. It’s not practical to update individual lines as there can be a lot of them and multiple updates will create unnecessary load and timing issues.

Below is a extract of the JSON data coming into the HTTP Request (variable record qty) from my Code Node that cleans up the data. Up till this point everything is working as expected:

[
{
"id": "b4a9f2ef-7862-ee11-ac3c-0a34284ced4a",
"InventoryID": {
"value": "BS6414GXAX"
},
"OrderQty": {
"value": 1
}
},
{
"id": "b5a9f2ef-7862-ee11-ac3c-0a34284ced4a",
"InventoryID": {
"value": "BS6414GXCX"
},
"OrderQty": {
"value": 2
}
},
{
"id": "b6a9f2ef-7862-ee11-ac3c-0a34284ced4a",
"InventoryID": {
"value": "BS6414GXEX"
},
"OrderQty": {
"value": 3
}
}
]

Basically I need the above data to look like the following JSON in my HTTP Request Body when I send it:

{
    "Details": [
        {
            "id": "7e8f3eb0-0463-ee11-ac3c-0a34284ced4a",
            "InventoryID": {
                "value": "BS6414GXAX"
            },
            "OrderQty": {
                "value": 1
            }
        },
        {
            "id": "7f8f3eb0-0463-ee11-ac3c-0a34284ced4a",
            "InventoryID": {
                "value": "BS6414GXCX"
            },
            "OrderQty": {
                "value": 2
            }
        },
        {
            "id": "808f3eb0-0463-ee11-ac3c-0a34284ced4a",
            "InventoryID": {
                "value": "BS6414GXEX"
            },
            "OrderQty": {
                "value": 3
            }
        }
    ]
}

With this Expression in the Body of the HTTP request I get the first record (which makes sense):

{
"Details": [
            {
                "id": "{{ $json["id"] }}",
                "InventoryID": {
                    "value": "{{ $json["InventoryID"]["value"] }}"
                },
                "OrderQty": {
                    "value": {{ $json["OrderQty"]["value"] }}
                }                
            }
]
}

But with execute once on I only get the first line updated…

Is this possible? Obviously I can only Execute the HTTP Request once, so my question is what does the Body Expression look like to loop through the data coming in from the Code node or do I need to do something in the Code node that makes it send just a single record with the JSON I need and then use in the Body.

Sorry if this is a simple question but I’m no expert in either JSON, Javascript or API’s :frowning:

Thanks,
Jason

Hi @jasonR :wave:

Thanks for all that information!

You’re looking for an array like this, right?

[
  {
    "Details": [
      {
        "id": "b4a9f2ef-7862-ee11-ac3c-0a34284ced4a",
        "InventoryID": {
          "value": "BS6414GXAX"
        },
        "OrderQty": {
          "value": 1
        }
      },
      {
        "id": "b4a9f2ef-7862-ee11-ac3c-0a34284ced4a",
        "InventoryID": {
          "value": "BS6414GXCX"
        },
        "OrderQty": {
          "value": 2
        }
      },
      {
        "id": "b4a9f2ef-7862-ee11-ac3c-0a34284ced4a",
        "InventoryID": {
          "value": "BS6414GXEX"
        },
        "OrderQty": {
          "value": 3
        }
      }
    ]
  }
]

You can achieve that like this:

Let me know if I was way off base though :sweat_smile:

3 Likes

Prefect, works a treat!

Thank you so much for your help @EmeraldHerald …I need to learn more Javascript :slight_smile:

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.