Configure Outbound REST Message API

mirza2
Kilo Contributor

Hi,

I have been stuck for a while to configure the HTTP method for Post using the Outbound REST Message.

Since the API will need me to send some information on the request body, such as: grant_type, resource, client_id, etc.

So, I made the configuration as below.

Screen Shot 2017-08-18 at 8.58.31 PM.png

But when I tested it, it looks like the Azure endpoint cannot recognize the Content to get the parameter for the request body with this error:

"error":"invalid_request","error_description":"AADSTS90014: The request body must contain the following parameter: 'grant_type'.

Screen Shot 2017-08-18 at 9.04.08 PM.png

I strongly believe this is because the problem on the Content-type, since I also got the same exact error when I am changing the Content-Type in another Content-type in Postman.

Screen Shot 2017-08-18 at 9.10.00 PM.png

Just for the info, this API have been tested working correctly if I use the Postman standard content-type with form data.

Screen Shot 2017-08-18 at 9.20.26 PM.png

Any suggestion or clue will much appreciated.

1 ACCEPTED SOLUTION

jarodm
Mega Guru

I think you just need to remove the curly brackets from your body and change the content-type to 'application/x-www-form-urlencoded'.



Example, using only code (no Outbound REST Message forms)


var restMessage = new sn_ws.RESTMessageV2();


restMessage.setEndpoint('http://httpbin.org/post');


restMessage.setHttpMethod('post');


//restMessage.setMIDServer('midserverbyname');


restMessage.setRequestHeader('content-type','application/x-www-form-urlencoded');


restMessage.setRequestHeader('accept','application/json');




restMessage.setRequestBody('form1=value1&form2=value2');




var response = restMessage.execute();


var httpStatus = response.getStatusCode();


var responseBody = response.haveError() ? response.getErrorMessage() : response.getBody();




if (httpStatus == '200'){


gs.info('Body: '+responseBody);




}else{


gs.info('HTTP Status: '+httpStatus);


gs.info('Error: '+responseBody);


}


View solution in original post

16 REPLIES 16

This issue has been nagging me since yesterday. Fixed it using the approach suggested by you.Thanks a lot for your help.

Binh Truong2
Mega Expert

Did you end up scripting all of this instead of using the REST forms? I tried it this way and still getting 401 Error


Hi,



I end up using the REST forms for the better maintainability, which my script calls this REST to invoke the API.


In case of 401 error I believe it's because of authorization problem, make sure you have setup the required user access/ permission on the remote end.


Binh Truong2
Mega Expert

I finally got it working using the same method. The problem I found was the syntax of the content block was not correct. I ran the same POST message on https://www.hurl.it/ and noticed the body message did not match. I copied the working body message from hurl and it worked.


Renuka8
Kilo Guru

Hi Mirza,

 

I am facing similar issue where you able to fix at your end, can you please provide me the steps.

 

@mirza