jsonrestpostmanmultiple-input

Multiple inputs - trying to send several request (http method: PUT)


I want to send different JSONs to an endpoint:

{{URL_API}}/products/{sku}

I need to update several information related to different products so i need to specify the product within the endpoint, i mean, i.e:

If you access this particular endpoint: {{URL_API}}/products/ you will get all the products but i need to specify the product that i want to update:

{{URL_API}}/products/99RE345GT

Take a look at this, i want to send a JSON like this:

{
    "sku": "99RE345GT",
    "price": "56665.0000",
    "status": 1,
    "group_prices": [
        {
            "group": "CLASS A",
            "price": 145198.794
        },
        {
            "group": "CLASS B",
            "price": 145198.794
        },
        {
            "group": "CLASS C",
            "price": 145198.794
        }
    ]
}

AND another one like this (both JSONs share the same structure BUT with different information):

{
    "sku": "98PA345GT",
    "price": "17534.0000",
    "status": 1,
    "group_prices": [
        {
            "group": "CLASS A",
            "price": 145198.794
        },
        {
            "group": "CLASS B",
            "price": 145198.794
        },
        {
            "group": "CLASS C",
            "price": 145198.794
        }
    ]
}

How can i do that?.I have already generated more than 200 JSONs for every product..

So, i have to update 200 products so i generated one JSON for every product, do you get me?

Following my example i would need to edit (somehow) the endpoint for every product and send a JSON, i.e:

since the first JSON has the SKU: 99RE345GT it should perform a http method: PUT over this enpoint:

{{URL_API}}/products/99RE345GT

Then, since the second JSON has the SKU: 98PA345GT it should perform a http method: PUT over this enpoint:

{{URL_API}}/products/98PA345GT

I have never done something like this before.. i read something about CSV + POSTMAN runner but i did not understand the way.

EDIT I was working on a file (Excel file) and i did this:

image

image2

So now i have all the different JSON for every product.

EDIT#2. It fails when it validates de Request_URL

I did this: 1)I created a new collection

image

2)I put this Request_url: {{URL_API}}/products/{{sku}}

3)I saved the changes and then, i went to the Collector Runner:

image

4)After cliking on the run button. i got this error message:

Invalid URL:

IMAGE


Solution

  • Have you tried adding those data sets to a CSV?

    https://learning.postman.com/docs/postman/collection-runs/working-with-data-files/

    If you have 2 column headers in a CSV file, one with sku and the other with requestBody - Add that variable value to the request body of the PUT request instead of the JSON.

    sku,requestBody
    99RE345GT, {JSON Payload}
    98PA345GT, {...} 
    

    Add a couple of values under those headings to start with, once you prove that it works in the collection Runner.

    Once you're happy, add the rest into the file. You may need to do some parsing of the JSON in the Pre-request Script but it should work.

    Alternatively, use this template in the PUT request body and this create a CSV withe same column heading as the values in the {{...}} syntax. The values in the datafile will resolve to the values in the request body.

    {
        "sku": "{{sku}}",
        "price": "{{price}}",
        "status": {{status}},
        "group_prices": [
            {
                "group": "{{groupA}}",
                "price": {{groupAPrice}} 
            },
            {
                "group": "{{groupB}}",
                "price": {{groupBPrice}}
            },
            {
                "group": "{{groupC}}",
                "price": {{groupCPrice}}
            }
        ]
    }
    

    The CSV might look like this:

    sku,price,status,groupA,groupAPrice,...
    99RE345GT,1234,1,Group A, 555
    98PA345GT,1235,1,Group A, 666