How to handle umlaute/mutations in AMP Script with REST API?

we are using AMPscript to transfer/send parts of our mailings we send through Email Studio (not Salesforce) to our REST service via HTTPPost to make the information available in an external CRM that is not Salesforce.

One part of the data is pulled from Data Extensions and hence is different for every email, however some parts are hard-coded and hence the same for every email and for every send to our REST Service.

Within this hard-coded part we have umlaute/mutations (ü). Now it seems like those umlaute are being encoded in a weird way by SFMC as we receive an error message – as far as we can see it is neither UTF-8 nor WindowsCodePage 1252.

The with .NET Core written REST-Service, that is receiving this Payload cannot handle this encoding and we are getting the following error message:

An unhandled exception was thrown by the application. Unable to translate bytes [FC] at index 92 from specified code page to Unicode.

However, when sending the same payload e.g. via Swagger or Postman it works… so the problem seems to lay somewhere in the sphere of SFMC.

Does anyone has an idea how to work around this to have AMPscript encoded in a proper way?

This is the AMPscript we are using (bold are the umlaute):

Hello %%Firstname%%,

this is a testmail to %%emailaddr%% for SFMC-6.

SubscriberKey: %%_subscriberkey%%
MemberId: %%memberid%%
EmailName: %%emailname_%%
JobId: %%jobid%%

Cheers and goodbye

%%[
var @JSON, @IsProductionMail

/* DONT EDIT THIS AREA */
/* =================== */

set @JSON = '{'
set @JSON = Concat(@JSON, '"subscriberKey": "', _subscriberkey,'",')

   /* EDITABLE AREA */
/* =================== */

/* LEITSATZ */
set @JSON = Concat(@JSON, '"leitsatz": "', 'Leitsatz **für** das Mailing', '",')


/* KURZBESCHREIBUNG */
set @JSON = Concat(@JSON, '"kurzbeschreibung": "', 'Eine kurze Beschreibung **für** das Mailing', '",')


/* SHAREPOINT-URL*/
set @JSON = Concat(@JSON, '"sharepointUrl": "', 'http://localhost:8080/pvs4', '"')

/* IS MAILING A PRODUCTION MAIL, DEFAULT  TRUE */
set @IsProductionMail = false

/* =================== */
/* END OF EDITABLE AREA */

/* DONT EDIT FOLLOWING LINE */
set @JSON = CONCAT(@JSON, '}')

/* Output JSON Object for preview and debugging and send to server for real send */
if _messagecontext == "SEND" then

 if @IsProductionMail == true then
  HTTPPost("https://www-services.hays.de/sfmc/v1/AmpScript", "application/json", @JSON, @response)
  OutputLine(v(@IsProductionMail))
 else
  HTTPPost("https://stage-services.hays.de/sfmc/v1/AmpScript", "application/json", @JSON, @response)
 endif

elseif _messagecontext == "PREVIEW" then

 OutputLine(v("Nur während der Vorschau zum Überprüfen der Werte sichtbar, NICHT im Mailing enthalten:"))
 OutputLine(v(@JSON))

endif

]%%

Answer

Unfortunately, you cannot set the encoding within the ampscript itself.

You should ask Salesforce support to change the default character set of the HTTP functions to UTF-8, as this issue is (as you already suspect yourself) due to conflicting encoding of special characters. It can easily be done within the scope of standard support, and should resolve this issue.

Attribution
Source : Link , Question Author : Greta Schellpeper , Answer Author : Lukas Lunow

Leave a Comment