cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Failure to do postJSON with numeric values in the JSON body

SOLVED
Soura
Aquamarine

Failure to do postJSON with numeric values in the JSON body

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);

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Failure to do postJSON with numeric values in the JSON body

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

View solution in original post

3 REPLIES 3

Re: Failure to do postJSON with numeric values in the JSON body

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

View solution in original post

Re: Failure to do postJSON with numeric values in the JSON body

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"
}
};  

 

Re: Failure to do postJSON with numeric values in the JSON body

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}";
Announcements

Check out the upcoming Expert Session: Understanding ThingWorx Navigate Licensing in Community "Customer Events" section.