简体   繁体   中英

Geting specific response body from response and put in a variable in Postman

I am trying to set the response in a variable but the response is just an ID, not an object. I used

var resposseBody=pm.response.json(); 

or

var resposseBody=pm.response.text();

but they didn't work. How can I set the response below in a variable?

"3707ff3d-2af9-4ea1-a6aa-08d9a8ee3cb3"

To save that value to a variable, add this to the Tests script:

pm.globals.set('id', pm.response.text());

This is an example using the global scope but the variable can be set at the Environment or Collection level.

There aren't many details in your question so it's difficult to offer any more of a solution than this one.

If the response is in json format, like

{"id":"3707ff3d-2af9-4ea1-a6aa-08d9a8ee3cb3"}

then you can get simply with

responseJsonData=pm.response.json();
responseId=responseJsonData.id;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM