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.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

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.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (3,377)