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.

gefragt vor 4 Jahren985 Aufrufe
1 Antwort
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

beantwortet vor 4 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen