Your question may already have an answer on the community forum. Please search for related topics, and then read through the guidelines before creating a new topic.
Hereās an outline with best practices for making your inquiry.
Iām trying to store a value from the response as a collection variable.
I use the command, pm.collectionVariables.set(ādetails_idā, responseJson.Details.id); in a test function.
Iāve tried two different requested to try and get the information. One is a GET request which gives the error Cannot read property āidā of undefined. The other is a PUT request which doesnāt give an error but when I look at the collection variables the current variable field is empty.
I might be missing some context here but is responseJson the response youāve saved before passing in the id key as a variable?
I tried to reproduce the issue but was able to store a value from the request response as a collection level variable. Hereās the snippet I used and a link to the public workspace/collection that youāre more than welcome to fork.
// Log response value in console - args.id is specific to the response I'm working with here.
console.log(pm.response.json().args.id);
// Set response value as a colleciton variable
pm.collectionVariables.set("details_id", pm.response.json().args.id)
Parsing the JSON response is one of the common challenges we face. Welcome to the club But this will get better once you are used to JSON responses.
I suggest you to use https://jsonpathfinder.com/, this helped me a lot during my initial testing days. Also I wrote a small blog here about it, feel free to read and provide your feedback! All the best
I originally tried that with the GET request and it didnāt work so I didnāt think to try it in the PUT request which does work. Any ideas why the GET request acts differently?
@jamesrollinsjr Yes for GET request, the response structure might be different. so the same snippet might not work. And I believe as per the documentation you should be using āPUTā request type for your request