- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2017 07:25 AM
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.
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'.
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.
Just for the info, this API have been tested working correctly if I use the Postman standard content-type with form data.
Any suggestion or clue will much appreciated.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2017 12:55 PM
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);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2017 12:55 PM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2017 12:29 AM
Hi Jarod,
I've tried with your suggestion to set the content-type with 'application/x-www-form-urlencoded', and write the content as below, and I can see the endpoint can read the content now (even with the new error come up).
I've learned that with 'application/x-www-form-urlencoded' content type, some special character such as: & - : + , / = need to be encoded first to UTF-8 format unless the endpoint will falsely parse the content. I can tackle this issue by replacing those characters with the correspond format in my script.
Anyway, if you have any other suggestion, or to make this more improved, you're welcome.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2017 09:46 PM
I hope everything got resolved and is testing well. I will likely be doing an Office365 integration later this year and will definitely return to this post to job my memory.
Jarod
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2017 11:23 PM
Hi Jarod,
I have tested for a couple days in my Dev environement, and seems it's just fine using the 'application/x-www-form-urlencoded' content type .
However, I am still curious why the Azure endpoint unable to read the "application/json" content-type which was sent by Outbound Rest Message form (which I set up in my first post). I have ever tried with the other URL end points, and it just working fine by putting json-formatted content in Outbound Rest Message.
Maybe I should go to the Hi Support to look for the answer.
Anyway, thank you for your help, and good luck with your work 🙂
P.S: I will continue to post the comment once I got feedback from the Support.