How do I pull a value from one request to be part of the URL of a second request?

I’m on day 1.5 of learning API, Postman, and coding in general. My working project is getting data from Qualtrics.

Here is the page from their support site:
https://api.qualtrics.com/reference#create-response-export-new

I’m stuck on one point. I think I found the answer but I don’t know enough to fully understand it yet.

To get data from Qualtrics requires three requests (I put only two below for brevity). The URL for the second request includes a value from the previous request. I’ve put them in a Collection.

How do I pull a piece of data from a request to be part of the next URL?

Here is part of the output of the first request:

{
    "result": {
        "progressId": "ES_736T0pNmloCLoyx",
        "percentComplete": 0.0,
        "status": "inProgress"
    }
}

In the 2nd request, the URL is: https://###.qualtrics.com/API/v3/surveys/###/export-responses/{{THEPROGRESSIDVALUEFROMABOVE}}

I read about setting an environment variable, and I included the following in the Tests section of the first request:

pm.environment.set("progress_key", WHATGOESHERE?);

I’m not sure what to put for the value so that it pulls the actual value from the result. Or is there some other way to do this? Thanks all!

Hey @fbrb99

This would be the reference to that value from the first request.

pm.response.json().result.progressId

The pm.response.json() part is parsing the full response and then using your example, it’s stepping down to that value.

If you’re setting an environment variable, ensure that you have created a file first and have that selected before making the first request. :grin:

1 Like

Alright! @danny-dainton thanks so much! That did it. I looked up a bit more about parsing and pm.response (I actually ended up at another post where you helped another noobie). Putting it all together, it is working and I am geeking out.

I am putting the final code below in case it helps others. If you have any input on how to clean it up, great. Otherwise, thank you. You’ve helped me take my first step into a much larger world. :laughing:

var jsonData = pm.response.json()
pm.response.json().result.progressId
var progressId = jsonData.result.progressId
pm.environment.set(“progress_key”, progressId);

1 Like

Glad to be of service :grin:

I guess you could just do this, instead of creating the other variable. It’s completely up to you though :grin:

let progressId = pm.response.json().result.progressId
pm.environment.set('progress_key', progressId);
1 Like

Thank you. I’m definitely using your revision. I figured there was a cleaner way, so thank you for the follow up. :grinning:

1 Like