Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Anonymous
Not applicable

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="my@email.com",
password= "mypassword"]),
response = Web.Contents(
url,
[
Headers = headers,
Content = postData
]
),

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

in
access_token

1 ACCEPTED SOLUTION
ImkeF
Community Champion
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".

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

2 REPLIES 2
ImkeF
Community Champion
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".

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Anonymous
Not applicable

Thanks. Had to rename token to access_token 👍

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.