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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Failure to do postJSON with numeric values in the JSON body

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

 

ACCEPTED SOLUTION

Accepted Solutions
mgoel
17-Peridot
(To:Soura)

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
mgoel
17-Peridot
(To:Soura)

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

Soura
13-Aquamarine
(To:mgoel)

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

 

Soura
13-Aquamarine
(To:Soura)

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


Top Tags