Skip to main content
14-Alexandrite
May 3, 2021
Solved

Failure to do postJSON with numeric values in the JSON body

  • May 3, 2021
  • 1 reply
  • 1563 views

Below is the snippet for my test code. The body works fine if it has string key-value pairs. But it fails when numeric values are passed in the body. Also, I cross checked by using Postman that this same snippet containing numeric body works OK. Any suggestion as to what could i try next would be appreciable.

var body = {
"List": {
"pgSize": 1,
"pgNumber": 50,
"State": "On"
}
};

var headers = {
"Authorization": me.AccessToken,
"Content-Type": "application/json",
"Accept-Encoding": "gzip, deflate, br",
"Accept": "application/json",
};
var params = {
proxyScheme: undefined /* STRING */ ,
headers: headers /* JSON */ ,
ignoreSSLErrors: undefined /* BOOLEAN */ ,
useNTLM: undefined /* BOOLEAN */ ,
workstation: undefined /* STRING */ ,
useProxy: undefined /* BOOLEAN */ ,
withCookies: undefined /* BOOLEAN */ ,
proxyHost: undefined /* STRING */ ,
url: url /* STRING */ ,
content: body /* JSON */ ,
timeout: undefined /* NUMBER */ ,
proxyPort: undefined /* INTEGER */ ,
password: undefined /* STRING */ ,
domain: undefined /* STRING */ ,
username: undefined /* STRING */
};
// responseJSON: JSON
var responseJSON = Resources["ContentLoaderFunctions"].PostJSON(params);

 

Best answer by mgoel

Hi @Soura 

 

Thanks for reaching out to us. Can you check below article if this is your requirement:

https://www.ptc.com/en/support/article/CS337595

 

Try using postText instea of PostJson in last line. Let me know in case of any question.

Regards,

Mohit

1 reply

mgoel5-Regular MemberAnswer
5-Regular Member
May 4, 2021

Hi @Soura 

 

Thanks for reaching out to us. Can you check below article if this is your requirement:

https://www.ptc.com/en/support/article/CS337595

 

Try using postText instea of PostJson in last line. Let me know in case of any question.

Regards,

Mohit

Soura14-AlexandriteAuthor
14-Alexandrite
May 4, 2021

Hi @mgoel,

Thanks for your response. I still get the same error(invalid request) with postText() call. Also, note that the body has a nested JSON object as shown below. Any suggestion on how to create the body as shown in your links using this JSON?

var body = {
"List": {
"pgSize": 1,
"pgNumber": 50,
"State": "On"
}
};  

 

Soura14-AlexandriteAuthor
14-Alexandrite
May 4, 2021

I edited the body as below and postText() works ok now.

var body ="{\r\n\"List\": {\r\n\"pgSize\": 1,\r\n\"pgNumber\": 50,\r\n\"State\": \"On\"\r\n}\r\n}";