
Thomas Wilkins (Customer) asked a question.
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:
- Am i passing the token correctly?
- how do i go about getting a new token, it seems running the auth curl doesnt do it.
Script in question
- $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
-
- $token = $request.access_token.ToString()
- $refreshtoken = $request.refresh_token.ToString()
-
- curl.exe -X GET --header 'Accept: application/json' --header 'Authorization: Bearer $token' 'http://wug.google.com:9644/api/v1/product/whoAmI'
- curl.exe -X GET --header 'Accept: application/json' --header 'Authorization: Bearer $token' 'http://wug.google.com:9644/api/v1/device-groups/0/devices'
- {
- "error": {
- "status": 401,
- "code": "TokenExpired",
- "message": "Token has expired or is otherwise invalid"
- }
I use double quote instead of single quote for it to work.
change from : 'Authorization: Bearer $token'
to : "Authorization: Bearer $token"