Application/x-www-form-urlencoded

When I test using Postman if I use the application/x-www-form-urlencoded header it the REST call I'm doing works. But when I try to do the same POST in purecloud we are getting "Message body is required." I have the Header of Content-Type application/x-www-form-urlencoded set on the data action in PureCloud. Anythoughts why this isn't working?

Could you upload an export of your action, with any sensitive bits redacted? A correlation ID from a failure would also be interesting to see.

Post-OutboundSMS-2019110774504.custom.json (1.6 KB)

Here is an error example

{ "status": 400, "code": "bad.request", "message": "The request could not be understood by the server due to malformed syntax.", "messageParams": {}, "contextId": "41154fae-e7a4-4c22-8094-2f476f3c6465", "details": [ { "errorCode": "ACTION.REMOTE_ENDPOINT" } ], "errors": [ { "status": 400, "code": "BAD_REQUEST", "message": "REST call for action execute failed. Message:Request to backend service failed. Response from web service: <?xml version='1.0' encoding='UTF-8'?>\n<TwilioResponse><RestException><Code>21602</Code><Message>Message body is required.</Message><MoreInfo>https://www.twilio.com/docs/errors/21602</MoreInfo><Status>400</Status></RestException></TwilioResponse> [41154fae-e7a4-4c22-8094-2f476f3c6465]", "messageParams": {}, "details": [], "errors": [] } ] }

The endpoint is expecting application/x-www-form-urlencoded, however you are passing in the raw input to your action, which is going to be JSON. Take a look at this thread for an example of how the request template should be formatted:

I guess I'm not sure exactly which part of that you are referring too but it ends with

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

Which I already have as a header. Did you look at the export I provided. If not hear is the configuration

{
"requestUrlTemplate": "https://api.twilio.com/2010-04-01/Accounts/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages",
"requestType": "POST",
"headers": {
"Content-Type": "application/x-www-form-urlencoded",
"Accept-Encoding": "gzip, deflate"
},
"requestTemplate": "${input.rawRequest}"
}

Also it is showing here as well
image

Hi I figured out what you were referring too in the other post.

The request body needed the $esc.url() method to encode it.

"To=esc.url(\"{input.To}")&From=esc.url(\"{input.From}")&Body=esc.url(\"{input.Body}")"

One question does Genesys plan to accept responses in anything other than application/json? Or is there a way to hard code the response around that restriction?

Hi agilo,

I'm glad you were able to figure out what I was talking about, sorry for not being more clear that it was the requestTemplate that needed to be changed.

We are currently not working on support responses other than application/json, however please post what you are looking for to https://purecloud.ideas.aha.io/ideas/ for future consideration.

--Jason

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.