Expand my Community achievements bar.

API JS cannot send Emojis in body

Avatar

Level 2

Hi,

I'm using an api to send messages but the problem is that when I insert an emoji in the body I get a 400 Bad request back here is my js code :

var jsonData = {
                "type": "text",                               
                "text": "body": "hello how are you ",
                token = "xxxxxxxxxxx",
                contentType = "application/json";
                
var req = new HttpClientRequest('https://exampleTestEndpoint.com/sendMessage/128192');
          req.header["Authorization"] = token;
          req.header["Content-Type"] =  contentType;
          req.method = "POST";
          var data = jsonData;
          req.body = JSON.stringify(data);
          req.execute();
          var resp = req.response;
          var code = resp.code;
          var body = JSON.parse(resp.body);

Then when I remove the emoji everything works normally, I tried with another api from another service and I had the same problem when I insert an emoji,
I also tried with the utf-8 code of the emoji but it still doesn't work.

 

Thank you in advance for your help!

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

API
2 Replies

Avatar

Level 6

Hi @AnasSpir05 ,

 

Seems there is problem with unicode configuration. I have send the same in past in subject line and below is method I have used and it worked, You can also try.

 

When inserting EMOJIs into a subject line, you must use the base string formatting like =?UTF-8?Q?=

Search the hexadecimal code of the emoji you want to insert (for example F0 9F 98 81 (you must remove \x) on the website http://apps.timwhitlock.info/emoji/tables/unicode)

Add the hexadecimal code in the base string format like the following:

=?UTF-8?Q?=F0=9F=98=81?=

 

This has worked for me, can you also try in JS.

 

Regards

Abhishek

 

 

Avatar

Level 2

Hello @aggabhi ,
thanks for your answer ,
I tried this method but the end result is that the text does not format and i get the utf8 code not the emoji ,
When I put in the body "=?UTF-8?Q?=F0=9F=98=81?=" the result is "=?UTF-8?Q?=F0=9F=98=81?=" not the emoji,
Regards,
Anas Rarhib.