Variable Value Assigned by Request Response Parsing

topstop
Sat, 25 Nov 2023 18:39:59 +0000
Help Hub

Variable passportToken is assigned to this request

{
  login(username: "unxx", password: "PWXX") {
    token
    status
    isPasswordExpired
  }

Response is

{token: "xxxxx....", status: true, isPasswordExpired: null}

In TESTs

// Save the login response to a variable
var tokenStr = pm.response.json().data.login;

//parse out the Key 'token' and get its value
 const key = Object.keys(tokenStr)[0];
 passportToken = Object.key(tokenStr[0])

 //set key value to passportToken variable

I’m getting a TypeError Object.key is not a function and need help to parse out the value for the key ‘token’

How is the variable just set to token: “xxxxx…” ?

6 posts - 2 participants