Reputation: 183
I have a GET
request in Postman. I am trying to set an Environment Variable for objectId
from the response body.
Here is my response body which is fine.
{
"odata.metadata": "https://graph.windows.net/myorganization/$metadata#directoryObjects/Microsoft.DirectoryServices.User",
"value": [
{
"odata.type": "Microsoft.DirectoryServices.User",
"objectType": "User",
"objectId": "0fjrkfkfc-50b1-4259-a778-sjvmfgr5bhjj",
}
]
}
I have tried the following to save the objectId as an Environment Variable but its not working. Any help will be appreciated.
var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("testtoken", jsonData.value[1]); // returns [object Object]
postman.setEnvironmentVariable("testtoken", jsonData.odata.metadata); // returns [object Object]
postman.setEnvironmentVariable("testtoken", jsonData.value); // returns [object Object],[object Object],[object Object], etc.
postman.setEnvironmentVariable("testtoken", jsonData.odata.metadata.value); // returns nothing
postman.setEnvironmentVariable("testtoken", jsonData.odata.metadata.value.objectId); // returns nothing
Upvotes: 1
Views: 1356
Reputation: 3038
You almost got it :)
jsonData.value[1].objectId
should work.
jsonData.value
will return an array containing single element - object with keys odata.type
, objectType
and objectId
.
Upvotes: 0