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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
AlexS2023
Helper I
Helper I

Cannot convert value to type List

Hi All,

 

I'm trying to use API's to pull data into PowerBI. Below is meant to pass my authentication details and return a bearer token for use in other queries. But I'm running into an error:

 

An error occurred in the ‘’ query. Expression.Error: We cannot convert the value "eyJhbGciOiJIUzUxMiJ9..." to type List.
Details:
Value=eyJhbGciOiJIUzUxMiJ9...
Type=[Type]

 

As you can see the function is finding a value, just not storing it correctly. Any ideas what I'm doing wrong?

 

Here is my function:

 

() =>
let
    body = [credentials=[username="MyUsername",password="MyPassword",company="MyCompany"]],
    Data=Json.Document(Web.Contents("https://secure.workforceready.eu/ta/rest/v1/login", 
        [Headers=[#"Content-Type"="application/json", #"Accept"="application/json",#"API-Key"="MyApiKey"], 
        Content=Json.FromValue(body)])),
    result = Record.Field(Data[token]{0},"token")
in
    result

 

 

TIA 🙂

 

1 ACCEPTED SOLUTION
ImkeF
Community Champion
Community Champion

Hi @AlexS2023 ,
please try this one:

() =>
let
    body = [credentials=[username="MyUsername",password="MyPassword",company="MyCompany"]],
    Data=Json.Document(Web.Contents("https://secure.workforceready.eu/ta/rest/v1/login", 
        [Headers=[#"Content-Type"="application/json", #"Accept"="application/json",#"API-Key"="MyApiKey"], 
        Content=Json.FromValue(body)])),
    result = Data[token]
in
    result

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

4 REPLIES 4
ImkeF
Community Champion
Community Champion

Hi @AlexS2023 ,
please try this one:

() =>
let
    body = [credentials=[username="MyUsername",password="MyPassword",company="MyCompany"]],
    Data=Json.Document(Web.Contents("https://secure.workforceready.eu/ta/rest/v1/login", 
        [Headers=[#"Content-Type"="application/json", #"Accept"="application/json",#"API-Key"="MyApiKey"], 
        Content=Json.FromValue(body)])),
    result = Data[token]
in
    result

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

It worked! And I guess I was overcomplicating things.

 

Thank you you're a life saver.

ImkeF
Community Champion
Community Champion

Hi @AlexS2023 ,
you could try omitting the {0} like so:

() =>
let
    body = [credentials=[username="MyUsername",password="MyPassword",company="MyCompany"]],
    Data=Json.Document(Web.Contents("https://secure.workforceready.eu/ta/rest/v1/login", 
        [Headers=[#"Content-Type"="application/json", #"Accept"="application/json",#"API-Key"="MyApiKey"], 
        Content=Json.FromValue(body)])),
    result = Record.Field(Data[token],"token")
in
    result

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

Thank you, sadly that didn't work. The new error message says it can't convert to type Record. I know there's something obvious I'm missing just can't see it yet 😄

 

An error occurred in the ‘’ query. Expression.Error: We cannot convert the value "eyJhbGciOiJIUzUxMiJ9..." to type Record.
Details:
Value=eyJhbGciOiJIUzUxMiJ9.eyJ...
Type=[Type]

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.