I need to send dynamic values into the request body


I am sending a request and it returns few records in response and it is displayed in page 1. I have multiple pages of response. After getting the first page response, i am printing the request body using “console.log(JSON.stringify(pm.request));” and copying it from the console and using it in pm.sendRequest() function to run the request inside a for loop. I want to pass a different page number to the request for every run inside the loop.

Below is my request body:

{“url”:{"hidden intentionally},

“header”:[hidden intentionally],


{“query”:“query ($start: String!, $end: String!, $page: Int!) \r\n{\r\n itemClassUpdates(start: $start, end: $end, page: $page) \r\n {\r\n page\r\n totalPages\r\n start\r\n end\r\n events \r\n {\r\n event\r\n itemClass\r\n {\r\n handle\r\n code\r\n erpCode\r\n description\r\n discontinued\r\n createUser\r\n createDate\r\n updateUser\r\n lastModified\r\n itemSubclasses\r\n {\r\n handle \r\n classHandle\r\n code\r\n erpCode\r\n description\r\n defaultUnitHandle\r\n discontinued\r\n createUser\r\n createDate\r\n updateUser\r\n lastModified\r\n }\r\n }\r\n }\r\n }\r\n}”,
“variables”:"{\r\n “start”: “2020-08-13T13:28:10Z”,\r\n “end”: “2020-08-13T13:55:18Z”,\r\n “page” : 1\r\n \r\n}"},

Is this possible to send dynamic page numbers through pm.sendRequest function into page variable in postman?


Yes it is possible, but depends on your API design as well. It is Pagination.

In your Query you have ($start: String!, $end: String!, $page: Int!)

Try defining a variable for your parameters and do a if loop till it reaches the end.

Do you know the total page count? If you do, you could set the variable like this:

const pageNumber = Math.trunc(Math.random() * totalPageCount);
pm.collectionVariables.set('pageNumber', pageNumber);