I am trying to figure out how to set a response value as a variable using a Test script so I can pass that value along to another call. All the tutorials I’ve seen do this AFTER setting the value in a Pre-request script, and the logic provided for that doesn’t seem to if you’re not setting the value yourself.
The response I get when I make the API call is as follows:
You’re using pm.response.text() here which isn’t required for a JSON response, as you can use .json() to get the data in a format that’s easily parsable.
This is what you would need to get the first object’s id value:
let response = pm.response.json();
pm.environment.set('folderID', response.data[0].id);
Ensure that you have an environment file created and selected or it will not capture the variable.
I wrote this a while ago about getting different values from a JSON response, it may help you here: