# Response body PM test

**URL:** <https://community.postman.com/t/response-body-pm-test/38004>\
**Category:** Help Hub\
**Tags:** tests, collections\
**Created:** [August 9, 2022, 2:15am UTC](https://community.postman.com/t/response-body-pm-test/38004 "2022-08-09T02:15:31Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![postmall\_desk](https://avatars.discourse-cdn.com/v4/letter/p/c0e974/32.png) [@postmall\_desk](https://community.postman.com/u/postmall_desk)\
**Post date:** [August 9, 2022, 2:15am UTC](https://community.postman.com/t/response-body-pm-test/38004/1 "2022-08-09T02:15:31Z")

</div>

Hi, can someone help me out with this issue  
I’m looking for a PM test: which pull json value from response body  
The response is in JSON

[{  
“id”: “2205440117001”,  
“account\_id”: “936125974001”,  
“ad\_keys”: null,  
“clip\_source\_video\_id”: null,  
“complete”: true,  
“created\_at”: “”,  
“created\_by”: {  
“type”: “unknown”  
},  
“cue\_points”: ,  
“custom\_fields”: {},  
“delivery\_type”: “dynamic\_origin”,  
“description”: “033\_mots\_k\_1\_02-4”,  
“digital\_master\_id”: null,  
“duration”: 252842,  
“economics”: “AD\_SUPPORTED”,  
“folder\_id”: “62c7dee1ecf84a72a5e7c502”,  
“geo”: null,  
“has\_digital\_master”: true,  
“images”: {  
“thumbnail”: {  
“src”: “”,  
“sources”: [{  
“src”: “”,  
“height”: 90,  
“width”: 160  
}]  
},  
“poster”: {  
“src”: “”,  
“sources”: [{  
“src”: “”,  
“height”: 480,  
“width”: 640  
}]  
}  
},  
“link”: null,  
“long\_description”: null,  
“name”: “mots\_k\_1\_02-4”,  
“original\_filename”: “En\_033.mp4”,  
“projection”: null,  
“published\_at”: “2013-03-05T22:12:46.099Z”,  
“reference\_id”: “En\_033”,  
“schedule”: null,  
“sharing”: null,  
“state”: “ACTIVE”,  
“tags”: [“mots”],  
“text\_tracks”: ,  
“transcripts”: ,  
“updated\_at”: “Z”,  
“updated\_by”: {  
“type”: “internal”  
},  
“playback\_rights\_id”: null  
}]

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [August 9, 2022, 9:23am UTC](https://community.postman.com/t/response-body-pm-test/38004/2 "2022-08-09T09:23:22Z")

</div>

Hi @postmall_desk

Which value are you trying to get from that response?

---

<div class="post-metadata">

**Author:** ![postmall\_desk](https://avatars.discourse-cdn.com/v4/letter/p/c0e974/32.png) [@postmall\_desk](https://community.postman.com/u/postmall_desk)\
**Post date:** [August 9, 2022, 12:40pm UTC](https://community.postman.com/t/response-body-pm-test/38004/3 "2022-08-09T12:40:56Z")

</div>

Hi @w4dd325 ,  
thanks for getting back so quickly,  
these are the values I need

{

“id”: “{{id}}”,

“account\_id”: “{{account\_id}}”,

“reference\_id”: “{{reference\_id}}”,

“name”: “{{name}}”

}

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [August 9, 2022, 1:36pm UTC](https://community.postman.com/t/response-body-pm-test/38004/4 "2022-08-09T13:36:56Z")

</div>

Try this;

```auto
const response = pm.response.json();

console.log('id = ' + response[0].id);
pm.collectionVariables.set("id", response[0].id);

console.log('account_id = ' + response[0].account_id);
pm.collectionVariables.set("account_id", response[0].account_id);

console.log('reference_id = ' + response[0].reference_id);
pm.collectionVariables.set("reference_id", response[0].reference_id);

console.log('name = ' + response[0].name);
pm.collectionVariables.set("name", response[0].name);

```

Note; Uses `**response[0]**` as the entire response is stored in an array (starts with `**[**` and ends with `**]**` … hopefully that makes sense).

Output;

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/8/827fca67f94379d6300a9188973721361d45bfcd.png)

Collection level variables saved;

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/0/078476fb5f944857598e3c938f0fe39389ba8841.png)

---

<div class="post-metadata">

**Author:** ![postmall\_desk](https://avatars.discourse-cdn.com/v4/letter/p/c0e974/32.png) [@postmall\_desk](https://community.postman.com/u/postmall_desk)\
**Post date:** [August 10, 2022, 7:19pm UTC](https://community.postman.com/t/response-body-pm-test/38004/5 "2022-08-10T19:19:00Z")

</div>

> [@w4dd325](#):
>
> ```auto
> const response = pm.response.json();
> 
> console.log('id = ' + response[0].id);
> pm.collectionVariables.set("id", response[0].id);
> 
> console.log('account_id = ' + response[0].account_id);
> pm.collectionVariables.set("account_id", response[0].account_id);
> 
> console.log('reference_id = ' + response[0].reference_id);
> pm.collectionVariables.set("reference_id", response[0].reference_id);
> 
> console.log('name = ' + response[0].name);
> pm.collectionVariables.set("name", response[0].name);
> 
> ```
> 
> Note; Uses `**response[0]**` as the entire response is stored in an array (starts with `**[**` and ends with `**]**` … hopefully that makes sense).

Thanks for your quick reply it worked, but every time I try to copy the response from the consol.log, it only copies a few lines.is the a way of exporting the response from the console.log?

---

<div class="post-metadata">

**Author:** ![postmall\_desk](https://avatars.discourse-cdn.com/v4/letter/p/c0e974/32.png) [@postmall\_desk](https://community.postman.com/u/postmall_desk)\
**Post date:** [August 10, 2022, 7:21pm UTC](https://community.postman.com/t/response-body-pm-test/38004/6 "2022-08-10T19:21:46Z")

</div>

Thanks for your quick reply, it works. But every time I try to copy the response from the console.log,it only copies a few lines\> Is there a way of exporting the body response from the console.log?  
Thanks  
Zara

---

<div class="post-metadata">

**Author:** ![Kristian](https://avatars.discourse-cdn.com/v4/letter/k/e8c25b/32.png) [@Kristian](https://community.postman.com/u/Kristian)\
**Post date:** [August 10, 2022, 11:44pm UTC](https://community.postman.com/t/response-body-pm-test/38004/7 "2022-08-10T23:44:57Z")

</div>

Do you want to actually test against the values, or just save the values to use in a later call. You can set them in your environment or your collection variables like w4dd325 suggested, or use the snippest on the right pane of the test tab to generate a test template for you.  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/f/b/fb4f2d3de54bede12887d9413542f1afd0850d8d.png)

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [August 11, 2022, 9:18am UTC](https://community.postman.com/t/response-body-pm-test/38004/8 "2022-08-11T09:18:41Z")

</div>

There is also this option,  
 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/0/05d69df9283208d9b943230ea6cd14b2e4e30f78.png)

You have this code in my example above;

```auto
const response = pm.response.json();

```

if you console.log it;

```auto
console.log(response);

```

then you would be able to copy it to the clipboard.

---

<div class="post-metadata">

**Author:** ![postmall\_desk](https://avatars.discourse-cdn.com/v4/letter/p/c0e974/32.png) [@postmall\_desk](https://community.postman.com/u/postmall_desk)\
**Post date:** [August 12, 2022, 1:32pm UTC](https://community.postman.com/t/response-body-pm-test/38004/9 "2022-08-12T13:32:41Z")

</div>

Thank you this worked. I have also started using Newnam as a library to run my collections. I’m getting an error  
[{“error\_code”: “UNAUTHORIZED”, “message”: “Permission denied.”}]. I downloaded my collection and environment.

newman.run({  
collection: require(‘./test\_collections\_scripts.postman\_collection.json’),  
environment: ‘./collection\_env.postman\_environment.json’,  
iterationData: ‘./test\_collections\_scripts.postman\_collection.json’',  
reporters: ‘cli’,  
}  
The iteration are running here is the response

 ![Screenshot-2022-08-12-14.25](https://us1.discourse-cdn.com/getpostman/original/2X/7/7c726101c9c5f225ebc99f7aedd06af67f1f966b.jpeg)  
 ![Screenshot-2022-08-12-14](https://us1.discourse-cdn.com/getpostman/original/2X/e/ea00f118e6773b498bfbb0614470181d5ff03001.jpeg)

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [December 12, 2024, 12:54pm UTC](https://community.postman.com/t/response-body-pm-test/38004/10 "2024-12-12T12:54:14Z")

</div>

Closed on December 12, 2024, 12:54pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
