How can I set a specific value to environment variable from the response

How can I set Id value to environment variable from the response?

I need to save only Id value for Env. variable.
In this example, I need only the 12345 value to save in the env variable.

This is the response:
{
“ResponseCode”: 0,
“Status”: 0,
“Data”: {
“Id”: 12345,
“Name”: “Created_By_Postman”,
“IdlFolder”: “Folder_Name”,
“FlowId”: “654321”,
“Type”: 2
}

}

Thanks!

Hi @Kyortush_13

You would need to grab the value and pass it to the environment variables like this;

const response = pm.response.json();
console.log(response.Data.Id);
pm.environment.set("id", response.Data.Id);

But also be aware that you would need to have your environment selected and it is also case-sensitive.

1 Like