Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X
Hello everybody,
I created a custom service with a JSON Input called "Data". I am trying to test this service via Postman.
Data will contain something like this:
[
{
"var1":5,
"var2":10
},
{
"var1":5,
"var2":10
}
]
Can someone tell me how i correctly pass this to Thingworx? So how do i have to format my body in postman? And in Thingworx Javascript do I have to parse the json first or is it already passed as i specify the input as json.
Thanks. I think the documentation on these things is really sparse
Solved! Go to Solution.
Hi Nicolas Jourdan,
tl;dr
To make it easy - if you need to pass an array in a format of JSON, just add a JSON type input parameter e.g. "data".
This array can be accessed by refering to "array" property, e.g.:
data.array.length;
data.array[0];
data.array[0].var1;
data.array[1].var2;
To pass that data from Postman or other tool, you need to pass as a body of the POST request:
{
"data": [
{
"var1": 1,
"var2": 2
},
{
"var1": 3,
"var2": 4
}
]
}
Please, remember to set a Header Content-Type: application/json and authorize with Application Key. If you expect any response, you can also set a Header Accept: application/json (if this format fits you).
Hope this helps.
Regards,
J.
Please check following article for details https://support.ptc.com/appserver/cs/view/solution.jsp?n=CS213601&lang=en_US
Added a screenshot here for reference:
Hi Nicolas Jourdan,
tl;dr
To make it easy - if you need to pass an array in a format of JSON, just add a JSON type input parameter e.g. "data".
This array can be accessed by refering to "array" property, e.g.:
data.array.length;
data.array[0];
data.array[0].var1;
data.array[1].var2;
To pass that data from Postman or other tool, you need to pass as a body of the POST request:
{
"data": [
{
"var1": 1,
"var2": 2
},
{
"var1": 3,
"var2": 4
}
]
}
Please, remember to set a Header Content-Type: application/json and authorize with Application Key. If you expect any response, you can also set a Header Accept: application/json (if this format fits you).
Hope this helps.
Regards,
J.
Thanks a lot its working now!! I also found the article posted by Ankit Gupta but it didnt work for me with the escaped quotation marks
Hello Nicolas Jourdan,
I'm glad I could help. If you found my answer correct and working, please consider to mark it as a "correct answer" to mark it as a reference for other users.
Regards,
J.