Creating Collection Runner with json Header and Detail sections

I’m trying to create a collection runner that will call the same endpoint URL, but will have various json strings (a collection of each single string we send). But when I created the file, I seem to be running into an issue with the formatting. Can I create a runner with a header and detail section and separate them for each subsequent push? Ideally, I would want to be able to add as many of these as needed.

Example

{
  "orderHeader": {
    "recordType": "01",
    "salesOrderNumber": "111111",
    "salesOrderName": "",
    "salesOrderID": "28106378111111120241111",
    "orderStatus": "04",
    "orderDate": "2024-11-11",
    "orderAmount": 111.11,
    "orderHoldReason": "Over Credit ",
    "expectedShipDate": "          ",
    "divisionCode": " ",
    "customerPONumber": "POSTMAN TEST1",
    "insideSalesPersonEmailID": "",
    "outsideSalesPersonEmailID": "[email protected]",
    "orderEnteredBy": "[email protected]",
    "forcedRoutingFlag": " ",
    "holdStatus": " ",
    "taxAmount": 0,
    "openOrderBalanceAmount": 1234.56
  },
  "customerDetails": {
    "customerNumber": "123412345",
    "branchNumber": "1234",
    "companyCode": "TEST123",
    "sourceSystem": "TEST"


  }
    "orderHeader": {
        "recordType": "01",
        "salesOrderNumber": "222222",
        "salesOrderName": "",
        "salesOrderID": "78023200022222220241111",
        "orderStatus": "04",
        "orderDate": "2024-11-11",
        "orderAmount": 222.22,
        "orderHoldReason": "Over Credit",
        "expectedShipDate": "",
        "divisionCode": "",
        "customerPONumber": "POSTMAN TEST2",
        "insideSalesPersonEmailID": "[email protected]",
        "outsideSalesPersonEmailID": "",
        "orderEnteredBy": "[email protected]",
        "forcedRoutingFlag": "",
        "holdStatus": "",
        "taxAmount": 0,
        "openOrderBalanceAmount": 9876.54,
        "arBalance": 0
    },
    "customerDetails": {
        "customerNumber": "987698765",
        "branchNumber": "9876",
        "companyCode": "TEST321",
        "sourceSystem": "TEST"
    }
}

Postman details:

Postman for Windows
Version11.19.0
UI version
11.19.0-ui-241023-0433
Desktop platform version
11.19.0
Architecture
x64
OS platform
win32 10.0.19045

The JSON data file needs to be an array of objects.

It will run once for each object in the array.

[
    {
        "orderHeader": {
            "recordType": "01",
            "salesOrderNumber": "111111",
            "salesOrderName": "",
            "salesOrderID": "28106378111111120241111",
            "orderStatus": "04",
            "orderDate": "2024-11-11",
            "orderAmount": 111.11,
            "orderHoldReason": "Over Credit ",
            "expectedShipDate": "          ",
            "divisionCode": " ",
            "customerPONumber": "POSTMAN TEST1",
            "insideSalesPersonEmailID": "",
            "outsideSalesPersonEmailID": "[email protected]",
            "orderEnteredBy": "[email protected]",
            "forcedRoutingFlag": " ",
            "holdStatus": " ",
            "taxAmount": 0,
            "openOrderBalanceAmount": 1234.56
        },
        "customerDetails": {
            "customerNumber": "123412345",
            "branchNumber": "1234",
            "companyCode": "TEST123",
            "sourceSystem": "TEST"
        }
    },
    {
        "orderHeader": {
            "recordType": "01",
            "salesOrderNumber": "222222",
            "salesOrderName": "",
            "salesOrderID": "78023200022222220241111",
            "orderStatus": "04",
            "orderDate": "2024-11-11",
            "orderAmount": 222.22,
            "orderHoldReason": "Over Credit",
            "expectedShipDate": "",
            "divisionCode": "",
            "customerPONumber": "POSTMAN TEST2",
            "insideSalesPersonEmailID": "[email protected]",
            "outsideSalesPersonEmailID": "",
            "orderEnteredBy": "[email protected]",
            "forcedRoutingFlag": "",
            "holdStatus": "",
            "taxAmount": 0,
            "openOrderBalanceAmount": 9876.54,
            "arBalance": 0
        },
        "customerDetails": {
            "customerNumber": "987698765",
            "branchNumber": "9876",
            "companyCode": "TEST321",
            "sourceSystem": "TEST"
        }
    }
]

I tried to call the value directly in the request body.

{
    "orderHeader": {{orderHeader}},
    "customerDetails": {{customerDetails}}
}

But this was returning [Object Object] instead of the value.

So I added a pre-request script to parse the object.

pm.collectionVariables.set("order",JSON.stringify(JSON.parse(JSON.stringify(pm.variables.get("orderHeader")))));
pm.collectionVariables.set("customer",JSON.stringify(JSON.parse(JSON.stringify(pm.variables.get("customerDetails")))));

You have to stringify the object first to return it as a string, then parse it, then stringify it again when saving it to the collection variable. Looks strange but it works.

Then you can use the new collection variables in the body.

{
    "orderHeader": {{order}},
    "customerDetails": {{customer}}
}

This seems to have done the trick.

Iteration 1…

Iteration 2…

1 Like

I was able to use this and get it to work! Thank you so much for the assistance.

1 Like

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