Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Get bearer token - Expression.Error

Hi, 
I'm trying to get a bearer token from a API so that I can refresh it to get data. 

I have the following code, and it returns the token, but it also returns an error. Any idea what I'm missing?

Error:
Expression.Error: The field 'token' of the record wasn't found.

Code:

let
url = "https://myurl/authenticate",
headers = [#"Content-Type" = "application/json"],
postData = Json.FromValue([email="[email protected]",
password= "mypassword"]),
response = Web.Contents(
url,
[
Headers = headers,
Content = postData
]
),

Data=Json.Document(response),
access_token=Data[token]

in
access_token

  • Hi Anonymous ,
    this means that the token that you have successfully retrieved doesn't sit in the field called "token", but in a different field instead.
    Please be aware that Power Query / M is case sensitive. So it might be Data[Token] instead.
    Otherwise please check the exact spelling of the field name in step "Data".

     

2 Replies

  • ImkeF's avatar
    ImkeF
    Community Champion

    Hi Anonymous ,
    this means that the token that you have successfully retrieved doesn't sit in the field called "token", but in a different field instead.
    Please be aware that Power Query / M is case sensitive. So it might be Data[Token] instead.
    Otherwise please check the exact spelling of the field name in step "Data".

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks. Had to rename token to access_token 👍