Send multiple json files and edit multiple params in API url

Hello everyone!
I’m quite new with Postman and I’m in trouble with a task that I need to accomplish.

I have multiple json files, like

File 1

{
"obj"="ALTX",
"field 1": 100,
"fiedl 2": 200,
}

File 2

{
"obj"="BERY"
"field 1": 300,
"fiedl 2": 400,
}

each file has to be sent via API Rest with an url like this

https://myurlapi.com/objects/{obj}?obj={obj}

where in both {obj} i have to set ALTX for File 1 and BERY for File 2

How could this be made?
I found some examples using csv but with a single json file with multiple object, while, in my situation, I have multiple json.
I could also think to merge them, but there’s still the problem to fill the fiel {obj} properly.

Can someone help me?
Thanks in advance

First of all, that is not valid JSON. The equals sign is not valid.

JSON is key\value pairs separated by colons “:”.

The Postman runner requires the JSON to be an array of objects.

It will then run once for each object.

[
    {
        "obj": "ALTX",
        "field 1": 100,
        "field 2": 200
    },
    {
        "obj": "BERY",
        "field 1": 300,
        "field 2": 400
    }
]

You will need to create a collection (or environment) variable called obj, and the value needs to point to the special “data” variable which will contain the current object in your data file. We can also target the obj key in your object at the same time by using {{data.obj}}.

For example…

image

You can then reference that in your URL but you need double curly brackets.

https://myurlapi.com/objects/{{obj}}?obj={{obj}}

1 Like

Thanks Mike! Your suggestions were incredibly good!
Now I’m able to manage GET with Postman Runner.

I’m in trouble with POST. I set the Post Run like this

But there’s no request body
“timestamp”:“2024-02-08T13:47:07.665+00:00”,“status”:400,“error”:“Bad Request”,“message”:"Required request body is missing: public java.lang.Object…

How colud it be possibile?

My example was using a JSON data file.

Your screenshot is showing a CSV? What happens if you click on “Preview”?

Oh, sorry… wrong screenshot. I tried with json and also with csv.
When I click “preview” postman gives me all the columns of the json (or the csv).
Could it be wrong formatting?

How have you setup the Post request?

I set up like this (there’s no variables expectedo as inpunt into the post url)


i left blank the body field given that i use the collection (am I wrong?)

If I use the Post request in the “classical” way as a single call with the body part included, it works.

The error is correct, as you currently have the request setup as raw\JSON, but have not included a body.

You need to put the elements into the JSON body.

You haven’t said what the body actually needs to look like for the POST request.

It’s usually raw\JSON, but you will need to confirm.

This will dictate what method you need use to populate the body.

Whether you need to manipulate the body, or whether you can use the data object like we did for the GET request.

1 Like

Thanks again Mike for your precious help. I did it! Everything works properly.

1 Like

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