Azure Logic App: how to make a x-www-form-encoded?

Viewed 5237

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.

4 Answers
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**
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

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.

Related