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

How to authenticate with a REST API that requires authentication with an application/x-www-form-urlencoded body

I am trying to setting a flow to call a REST API. I set up an HTTP step.  How do you do this in Flows? I can API call just fine.

 

The problem I'm having is that the REST API requires me to authenticate and get an access token using. I always get invalid grant type because I can't seem to pass application/x-www-form-urlencoded which is requires.

 

POST:

https://www.mywebsite.com/token

 

Header

accept application/json

application/x-www-form-urlencoded

 

Javascript equivalent that works is:

var settings = {
  "method""POST",
  "timeout"0,
  "headers": {
    "Accept""application/json",
    "Content-Type""application/x-www-form-urlencoded"
  },
  "data": {
    "grant_type""password",
    "username""XXXXX",
    "password""XXXXX"
  }
};

$.ajax(settings).done(function (response) {
  console.log(response);
});

 

grant_type: password

username:XXXXX

password:XXXXX

 

 

1 REPLY 1
eliotcole
Super User
Super User

When you're passing the token in the URL/URI, have you tried passing it using the encodeUriComponent() function in an expression?

 

I'm not suggesting this will resolve the issue, but maybe there are characters that aren't being passed correctly in the URI.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Power Automate Designer Feedback_carousel.jpg

Help make Flow Design easier

Are you new to designing flows? What is your biggest struggle with Power Automate Designer? Help us make it more user friendly!

Top Solution Authors
Top Kudoed Authors
Users online (1,202)