How to set multiple json data to a one time request using external json file

#1

Hi all, I am new to postman and I have a requirement to send a http request to create a multiple variables in a single aspect.
ie: one aspect has many variables.

for your information: to create something new in the server I have to use PUT method. And it worked fine.

so this is my request body.

data to the request body “variables” , I am passing through external json file in my local machine.

so this is my json file.

so when I use this file to run the collection using Runner , It was only created one object. (json file has 3 objects) other two objects are not created.

how can I read this json file in one go.

Any help would be appreciated.

#2

The moment you upload the JSON file, the collection runner reads the number of entries that are there and sets the iteration count, like so:
image

Then as soon as you press Run, each request will now run for 3 times in succession, and data for each iteration will be passed accordingly.

Question is, when you run your collection do you see these iterations being performed?
When you upload the data file, do you see the iteration count set as 3?
If not, can you make it 3 and check?

#3

@sivcan , thank you for the quick reply.
here I attach what i performed. so as you can see the preview data.

#4

That’s correct, that means runner is providing the correct data and running the correct number of iterations for your request.
Can you check the runner view?

It should look something like this (Showing the iterations distinctly):

That means, it’s correctly hitting your server also with the correct data.
You might want to check your server code, the issue probably lies there.

#5

this where I getting problem, here I attached the run result.
so the first json object is created, but other two are not created.

#6

As I can see in the image that you shared, you’re getting a 402 - Precondition Failed error.
image

This error is being thrown by the server, you should check the server code as to why this is failing.
For more help, you can use the Postman Console to view each request being sent out in a separate view.

To open the Postman Console - View > Show Postman Console
image

#7

It seems like variables array index always showing 0. It should something like 0,1,2 , is it ?
if that’s the case how can I write a pre-request-test to loop through the json file , if possible ?

server code is out of my control! I’m using thier apis.

#8

Your Request Body has an array called variables which has only 1 entry - https://sjc1.discourse-cdn.com/business6/uploads/getpostman/original/2X/9/9773d75e8c6843b4b97cb7325844b1e843093551.png

So, when an array is like ->

let arr = [{ variables: 2}]

then array only has only one item which can be accessed using the 0th index.
That’s why the index won’t change in the iterations because it’s just a view which is listing the items in the array, irrespective of anything going to the server.
Also, the data from Postman is going as expected as I can see from the screenshot.

You should read the error message in the response body if there is any from the api.