Using Response to format URL for next Query

I am very new to working with APIs and I am not at all a programmer. That said, I am trying!

What I need to do is format a URL from my previous querys response, and its working, but I have formatting issues.

Query A is returning a list of ids like this:

“resources”: [


What I need to do is pass the resources to the URL for my next query like:… and so on.

What is happening is this:,fa79f22a729d239f288a3be0&,74d6301c15314ec2da473.

Can anyone point me in the right direction here? I am lost!


Hey @sKtwsU6mjAuNcck! Welcome to the Postman community :tada:

I understand you would like to pass each element in the response array from the previous request separately to a query parameter, correct?

You can pass the values to the next request using environment variable (place the following code in the Test tab of the previous request):

const resources = pm.response.json().resources
let queryParamString = ''
resources.forEach((id, index, array) => {
    queryParamString += index!==array.length-1 ? `ids=${id}&` : `ids=${id}`
pm.environment.set('queryParamString', queryParamString)

And then you can replace the next request with following:{{queryParamString}}

I hope this helps!
Please let me know if you have further questions :smiley:

This works perfectly. What I ultimately need is for this to be a python script and I dont know much about Python. I tried going to code and selecting python, but it doesnt seem to work and the Test script doesnt appear in the Python code. Any idea on how someone with 0 knowledge of Python can turn these into a functional python script?

Hey @sKtwsU6mjAuNcck,

Thanks for getting back!
I am glad that the script works for you :smiley:

In Python, it would be as follows (you will need to replace the array values):

resources = ["a", "b", "c"]
string = ""
for i, id in enumerate(resources):
    if i != len(resources)-1:
        string+= id + "&"
        string+= id


Hope this helps!
Please let me know if you have further questions :wink: