cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
joakims
New Member

(400) Bad Request using Web.Contents to connect to REST API via Oauth2

Hi,

 

I'm having issues connecting to an API using Oauth2 authentifiation, as it generates the error (400) Bad Request.

I tried to download Fiddler, and I'm not really sure how to use it.. Any help here would be much appreciated.

 

Here's an example from the documentation (Javascript):

var xmlhttprequest = new XMLHttpRequest(); xmlhttprequest.open("POST", "https://demo.fatman.fi/identity/connect/token", false); xmlhttprequest.setRequestHeader("Authorization", "Basic YWIzMWY4NmM0YzE2NGUxZWE3M2EyNGU3NDE1MTM0Yjk6UnlTUFJKamgzaEZnS3dsYVY4Vjh1dTQ 4VQ==");  xmlhttprequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded") xmlhttprequest.send("grant_type=client_credentials&scope=api") xmlhttprequest.responseTex

 

Here's the M code:

let
apiUrl = "https://demo.fatman.fi/identity/connect/token",
options = [Content =Text.ToBinary("grant_type=client_credentials&scope=api"),
                 Headers= [
                 #"Authorization"="Basic xxxxxxxx",
                 #"Content-Type"="application/x-www-form-urlencoded"]

                 ],
result = Web.Contents(apiUrl, options)
in
result

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Moderator v-yuezhe-msft
Moderator

Re: (400) Bad Request using Web.Contents to connect to REST API via Oauth2

@joakims,

There is a similar blog providing details about how to connect to REST API via OAuth2 in Power BI, you can following the instructions in this blog to connect to your data source.

If you still get error, you can use Fiddler to track the process following the guide in this video.

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Moderator v-yuezhe-msft
Moderator

Re: (400) Bad Request using Web.Contents to connect to REST API via Oauth2

@joakims,

There is a similar blog providing details about how to connect to REST API via OAuth2 in Power BI, you can following the instructions in this blog to connect to your data source.

If you still get error, you can use Fiddler to track the process following the guide in this video.

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

joakims
New Member

Re: (400) Bad Request using Web.Contents to connect to REST API via Oauth2

 

I had a little time to revisit the code, and noticed I had left the "<>" marks for the base hashing. I simply removed them, and now it works. Thanks for the help!

Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Join THE global Microsoft Power Platform event series.

Join THE global Power Platform event series.

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors