API JS cannot send Emojis in body | Community
Skip to main content
Level 2
July 17, 2023
Question

API JS cannot send Emojis in body

  • July 17, 2023
  • 1 reply
  • 881 views

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!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

Level 5
July 17, 2023

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

 

 

Level 2
September 6, 2023

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.