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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Amar-Agnihotri
Resolver I
Resolver I

We found extra characters at the end of JSON input

 I have created a function in power query to get the authorization code which i will use to generate the access token to call the REST api. Here is the function definition - 

 

() =>
let
body = "client_id=021ed4a0-7883-42fd-82c0-0566481cc851&response_type=code&redirect_uri=http://localhost:44300/&response_mode=query&scope=openid&state=12345",
Data= Json.Document(Web.Contents("https://login.microsoftonline.com/common/oauth2/authorize/",
[Headers=[#"Content-Type"="application/x-www-form-urlencoded"],
Content=Text.ToBinary(body)
]))
in
Data

 

 

 

But when i am invoking this function i am getting this error

 

AmarAgnihotri_0-1649863192297.png

Can anybody tell me how to resolvre this one . 

6 REPLIES 6
ImkeF
Community Champion
Community Champion

Hi @Amar-Agnihotri ,
I would try to call the API whithout instantly trying to convert the result to JSON like so:


let
body = "client_id=021ed4a0-7883-42fd-82c0-0566481cc851&response_type=code&redirect_uri=http://localhost:44300/&response_mode=query&scope=openid&state=12345",
Data= Web.Contents("https://login.microsoftonline.com/common/oauth2/authorize/",
[Headers=[#"Content-Type"="application/x-www-form-urlencoded"],
Content=Text.ToBinary(body)
])
in
Data

 

This will allow you to check the format of the API return.

BTW: Your response parameter in the header suggests that you are getting a query back. That could explain the mismatch.

 

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

hi @ImkeF 

 

I changed the code as you can see 

 

AmarAgnihotri_0-1650266576051.png

But when i am invoking the function it is returning this  -

AmarAgnihotri_1-1650266615951.png

 

I think this makes no sense ..  No data ios returned 

Yes, that's looking good.
Now, just click or doublecklick on the globe-symbol and the content should automatically extract further.

 

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

Hi @ImkeF 

I tried but it is showing empty table 

AmarAgnihotri_0-1650361261052.png

 

 

v-jingzhang
Community Support
Community Support

Hi @Amar-Agnihotri 

 

It seems the response result of the Web.Contents("https://login.microsoftonline.com...................) section is not a standard JSON type data, so this error appears when using Json.Document() to return the content. You can remove the "()=>" characters to convert it back into a common query and check its result. 

 

Best Regards,
Community Support Team _ Jing

@v-jingzhang Hello,

 

Does this makes sense . I changed the code . It looks like this now -

 

AmarAgnihotri_2-1650266836719.png

 

How will it generate the auth code?

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors