Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

HTTP API Call Issue from Adobe campaign classic Java script

Avatar

Avatar
Level 1
ujjyals87155580
Level 1

Likes

0 likes

Total Posts

4 posts

Correct Reply

0 solutions
View profile

Avatar
Level 1
ujjyals87155580
Level 1

Likes

0 likes

Total Posts

4 posts

Correct Reply

0 solutions
View profile
ujjyals87155580
Level 1

09-07-2020

Hi experts,

 

I am making a HTTP API call from javascript. The API takes a JSON object as the request body. So I am using the following script for creating the JSON object for request

 

var eml = "abc.com";

var fst = "abc";

var lst = "com";

var obj = {email: eml, first_name: fst, last_name: lst};

httpRequest.body = JSON.stringify(obj);

 

When I make this call the API responds correctly.

But if the variables : eml , fst , lst  has double byte characters like Japanese, Chinese, Korean characters, then the same API call is failing with a error "Request Body should be a valid JSON object."

 

If I call the API from Postman, with the double byte character set up, then API works.

Any idea why it is failing from Adobe campaign javascript?

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Validate 1
MVP
_Manoj_Kumar
MVP

Likes

104 likes

Total Posts

301 posts

Correct Reply

97 solutions
Top badges earned
Validate 1
Contributor
Ignite 1
Shape 1
Give Back 5
View profile

Avatar
Validate 1
MVP
_Manoj_Kumar
MVP

Likes

104 likes

Total Posts

301 posts

Correct Reply

97 solutions
Top badges earned
Validate 1
Contributor
Ignite 1
Shape 1
Give Back 5
View profile
_Manoj_Kumar
MVP

09-07-2020

Hello @ujjyals87155580,

 

Do you have character coding set up in the Headers?

 

It will look something like this

http.header["Content-Type"] = "application/json;charset=utf-8";

If this does not work

Try this  before adding it to json object.

JSON.parse(eml)

 

Let me know if that works.

Thanks

 

Answers (1)

Answers (1)

Avatar

Avatar
Contributor
MVP
Milan_Vucetic
MVP

Likes

161 likes

Total Posts

380 posts

Correct Reply

134 solutions
Top badges earned
Contributor
Springboard
Shape 1
Validate 25
Validate 10
View profile

Avatar
Contributor
MVP
Milan_Vucetic
MVP

Likes

161 likes

Total Posts

380 posts

Correct Reply

134 solutions
Top badges earned
Contributor
Springboard
Shape 1
Validate 25
Validate 10
View profile
Milan_Vucetic
MVP

10-07-2020

Hi @ujjyals87155580,

take care of escaping special characters.

You may call a following function to escape text before putting it in JSON:

 

String.prototype.escapeSpecialCharacters = function() {
return this.replace(/\\n/g, "\\n")
.replace(/\\'/g, "\\'")
.replace(/\\"/g, '\\"')
.replace(/\\&/g, "\\&")
.replace(/\\r/g, "\\r")
.replace(/\\t/g, "\\t")
.replace(/\\b/g, "\\b")
.replace(/\\f/g, "\\f");
}; 

 

Regards,

Milan