RESTAPI script and Tokens

HI, I was hoping someone could help me and figure out if I am doing something wrong. I can authorize fine with the restapi, get a token, but when trying to use that token to do simple tasks. I keep getting tokenexpired.

 

2 question:

  1. Am i passing the token correctly?
  2. how do i go about getting a new token, it seems running the auth curl doesnt do it.

 

Script in question

  1. $Request = curl.exe -k --request POST --url http://wug.google.com:9644/api/v1/token --data "grant_type=password&username=WugAutomation&password=superCOOLpassword" | ConvertFrom-Json
  2.  
  3. $token = $request.access_token.ToString()
  4. $refreshtoken = $request.refresh_token.ToString()
  5.  
  6. curl.exe -X GET --header 'Accept: application/json' --header 'Authorization: Bearer $token' 'http://wug.google.com:9644/api/v1/product/whoAmI'
  7. curl.exe -X GET --header 'Accept: application/json' --header 'Authorization: Bearer $token' 'http://wug.google.com:9644/api/v1/device-groups/0/devices'
  1. {
  2. "error": {
  3. "status": 401,
  4. "code": "TokenExpired",
  5. "message": "Token has expired or is otherwise invalid"
  6. }

 


  • Ks Tan (Asia Vad)

    I use double quote instead of single quote for it to work.

    change from : 'Authorization: Bearer $token'

    to : "Authorization: Bearer $token"