I get stack. Need to set the variable in the array.
Name, email, uuid. To use they in the next request.
( Under the Tests tab of the get Canadian user
request, initialize collection variables to store the data returned from the API for the first user in the response object. This information is required for the next request.)
{
“results”: [
{
“gender”: “male”,
“name”: {
“title”: “Mr”,
“first”: “Samuel”,
“last”: “Patel”
},
“location”: {
“street”: {
“number”: 3122,
“name”: “Vimy St”
},
“city”: “Borden”,
“state”: “British Columbia”,
“country”: “Canada”,
“postcode”: “Y0E 7X2”,
“coordinates”: {
“latitude”: “22.6723”,
“longitude”: “-75.7561”
},
“timezone”: {
“offset”: “-6:00”,
“description”: “Central Time (US & Canada), Mexico City”
}
},
“email”: “samuel.patel@example.com”,
“login”: {
“uuid”: “db34f121-9e05-4bb7-a4cf-af3c0125c848”,
“username”: “smallwolf673”,
“password”: “dolemite”,
“salt”: “L5cvRSBA”,
“md5”: “4481421a17f8c0ac6e8edb0f9c78c0e5”,
“sha1”: “5c4f67360c861942fa099951b5b360a5830d4ec4”,
“sha256”: “3413a771c221efd1c00929b596f7951f82b3efa4d61ee17c1cec485c17a1d1e7”
},
“dob”: {
“date”: “1998-01-11T05:42:24.332Z”,
“age”: 25
},
“registered”: {
“date”: “2006-08-23T16:16:47.198Z”,
“age”: 16
},
“phone”: “B01 J75-2546”,
“cell”: “B34 R17-5993”,
“id”: {
“name”: “SIN”,
“value”: “253181994”
},
“picture”: {
“large”: “https://randomuser.me/api/portraits/men/77.jpg”,
“medium”: “https://randomuser.me/api/portraits/med/men/77.jpg”,
“thumbnail”: “https://randomuser.me/api/portraits/thumb/men/77.jpg”
},
“nat”: “CA”
}
],
“info”: {
“seed”: “ee379f59e2e1f802”,
“results”: 1,
“page”: 1,
“version”: “1.4”
}
}
I tried
var jsonData = JSON.parse(responseBody);
console.log(jsonData[0].name.first);
pm.environment.set(“Name”, jsonData[0].name.first);
In console I see TypeError: Cannot read properties of undefined (reading ‘first’)
Help me to set Name, email, uuid. To use they in the next request.