Need help in extracting the value

Hi All,

I have store the below result in a environment variable called Key_value and want to retrieve the Id value from this variable and used it in the next post request. Can some one help me how to achieve the same.

{
“objects”: [
{
“id”: “9yQeoXHnw0ykkfKz5zzZCL”,
“path”: “XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX”,
“type”: “MTT”,
“description”: “”,
“updatedBy”: “System”,
“updateTime”: “2018-07-10T09:07:33Z”
}
]
}

Hey @saveuser12345,

I wrote this post that might help you out:

Hi @saveuser12345,

Go ahead and execute the below test script

key = JSON.parse(pm.environment.get("Key_value"));
id = key.objects[0].id;

HI ahmed,

I have used the above script in the pre request part of post request and i am using body as mentioned below and it is throwing error here Id is the value retreived from above scripts . i have to use the value “9yQeoXHnw0ykkfKz5zzZCL” in my body of next request which is what i am expecting in the {{id}} value.

{
“@type”: “job”,
“taskFederatedId”:"{{id}}",
“taskType”: “MTT”
}

Hi @saveuser12345,

For you to use the extracted value of id in the body of the request, you would need to set the value of id to an environment or global variable as given below and then access it using the double brackets in the request:

key = JSON.parse(pm.environment.get("Key_value"));
pm.environment.set("id", key.objects[0].id);
or
pm.globals.set("id", key.objects[0].id);   

Hi Ahmed,

Thanks that worked fine for me. but may i understand objects[0] means what in your statement.

Hi Ahmed,

Can you help in the below past as well.

Download file when send request.

Hi @saveuser12345,

I think it would be better if you follow up in the mentioned thread if you are still facing issues using the collection .