Hi,
with request GET i get a response and ièm trying to set a data from the response as global variable.
i tried this:
var responseJson = pm.response.json();
pm.globals.set(‘idReques’, (responseJson.idRequest[0]).toString());
returns: TypeError: Cannot read property ‘0’ of undefined
pm.globals.set(‘idReques’, (responseJson.idRequest).toString());
returns: There was an error in evaluating the test script: JSONError: Unexpected token ‘<’ at 1:1 ^
Hi,
i can t share screenshot.
but here is what iè m doing:
var responseJson = pm.response.json();
pm.globals.set(‘idReques’, (responseJson.idRequest));
there is no error but the value of idRequest is empty when i check global variable:
i can see it created the variable idRequest but its value is empty.
That response sample is very helpful I think The initial square bracket indicates that the response is actually inside an array, so you need to indicate that you want to read the values from within the first item of the array -
var responseJson = pm.response.json();
pm.globals.set('idReques', (responseJson[0].idRequest));
Here is a quick example I made, using a variable with the same structure as your response, which demonstrates this: