4

I'm trying to make a request with Content-Type x-www-form-urlencoded that works perfectly in postman but does not work in Azure Logic App I receive a Bad Request response for missing parameters, like I'd not send enything.

I'm using the Http action.

The body value is param1=value1&param2=value2, but I tried other formats.

Paulo Henrique
  • 83
  • 2
  • 10
  • Can you post the JSON code of your Logic App? Have you tried sending the request to https://requestb.in/ to inspect how the Logic App is sending the body? – Paco de la Cruz Aug 14 '17 at 06:13

5 Answers5

6
Try out the below solution . Its working for me .

concat(
'grant_type=',encodeUriComponent('authorization_code'),
'&client_id=',encodeUriComponent('xxx'),
'&client_secret=',encodeUriComponent('xxx'),
'&redirect_uri=',encodeUriComponent('xxx'),
'&scope=',encodeUriComponent('xxx'),
'&code=',encodeUriComponent(triggerOutputs()['relativePathParameters']['code'])).

Here code is dynamic parameter coming from the previous flow's query parameter.

NOTE : **Do not forget to specify in header as Content-Type ->>>> application/x-www-form-urlencoded**
Roushan
  • 264
  • 2
  • 14
5
HTTP Method: POST
URI : https://xxx/oauth2/token

In Headers section, add the below content-type:

Content-Type: application/x-www-form-urlencoded

And in the Body, add:

grant_type=xxx&client_id=xxx&resource=xxx&client_secret=xxx
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
pavan
  • 51
  • 1
  • 2
3

Answering this one, as I needed to make a call like this myself, today. As Assaf mentions above, the request indeed has to be urlEncoded and a lot of times you want to compose the actual message payload.

Also, make sure to add the Content-Type header in the HTTP action with value application/x-www-form-urlencoded

therefore, you can use the following code to combine variables that get urlEncoded:

concat('token=', **encodeUriComponent**(body('ApplicationToken')?['value']),'&user=', **encodeUriComponent**(body('UserToken')?['value']),'&title=Stock+Order+Status+Changed&message=to+do')

When using the concat function (in composing), the curly braces are not needed.

Sam Vanhoutte
  • 3,247
  • 27
  • 48
1

First of all the body needs to be:

{  param1=value1&param2=value2 }

(i.e. surround with {})

That said, value1 and value2 should be url encoded. If they are a simple string (e..g a_b) then this would be find as is but if it is for exmaple https://a.b it should be converted to https%3A%2F%2Fa.b

The easiest way I found to do this is to use https://www.urlencoder.org/ to convert it. convert each param separately and put the converted value instead of the original one.

Assaf Mendelson
  • 12,701
  • 5
  • 47
  • 56
0

Here is the screenshot from the solution that works for me, I hope it will be helpful. This is example with Microsoft Graph API but will work with any other scenario:

enter image description here

Daniel Krzyczkowski
  • 2,732
  • 2
  • 20
  • 30