Newline encoding in url to SNS Service

0

Hi,

I am triggering the SNS Service through the API Gateway.
My RequestBody looks like this:
{
"sender_id": "Alias",
"phone_number": "+4912345678",
"message_text": "Break \n here"
}

The Url Query Parameter is mapped like this:
Message method.request.body.message_text
Action Publish

etc.
This alone should work fine, but it isn't, as it's passed to the SNS service via URL and the \n gets decoded to %5Cn.
"Action=Publish&Message=Break_%5Cn_here"
This should be passed as %0A. Even writing "Break %0A here" in the message is not working as the % is then urlencoded as %25, which results in %250A in the URL and a '%0A' in the received SMS.

I tried overwriting the Message through a Mapping Template and using $util.javaScriptEscape and so on.. Nothing works, it's always too heavy encoded. Is there a way to trick AWS into not doing this? Or a way to pass the Message other than through the URL Query?

I hope this request is detailed enough, thanks in advance.

asked 4 years ago967 views
1 Answer
0

Thanks to the AWS Support the problem has been solved. It was wrong to use URL Query Parameters. I removed all of them.
I needed one HTTP Header: Content-Type: 'application/x-www-form-urlencoded'

Then I used a Messaging Template like this:
#set($message = $input.path('$.message_text'))
#set($phoneNumber = $input.path('$.phone_number'))
Action=Publish&PhoneNumber=$util.urlEncode($phoneNumber)&Message=$util.urlEncode($message)&MessageAttributes.entry.1.Name=AWS.SNS.SMS.SenderID&MessageAttributes.entry.1.Value.DataType=String&MessageAttributes.entry.1.Value.StringValue=Alias

Having my JSON Object in the Request like this:
{
"phone_number": "+4912345678",
"message_text": "Break\nHere",
"sender_id":"Alias"
}

Works perfectly fine with a line break

answered 4 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions