Forum Discussion
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
Can anybody tell me how to resolvre this one .
6 Replies
- v-jingzhang
Community Support
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- Amar-Agnihotri
Resolver I
v-jingzhang Hello,
Does this makes sense . I changed the code . It looks like this now -
How will it generate the auth code?
- ImkeF
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 DataThis 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.
- Amar-Agnihotri
Resolver I
hi ImkeF
I changed the code as you can see
But when i am invoking the function it is returning this -
I think this makes no sense .. No data ios returned
- ImkeF
Community Champion
Yes, that's looking good.
Now, just click or doublecklick on the globe-symbol and the content should automatically extract further.