Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X
The question of accessing the full POST body has not been addressed yet in any of the documentation/community posts.
With the following destination:
https://.../Thingworx/Things/testthing/Services/TestRest?appKey=<appKey>&Content-Type=application/json&method=post
and Body:
{"Value1":11,"Value2":22,"Value3":33}
In the 'TestRest' service, I can logger.warn the body values if the TestRest service has inputs named 'Value1','Value2' and 'Value3'.
But if I don't know what those parameters are, how do I simply access the full message body that was sent?
Hi Matt,
I would try to pass the whole body in CSV format (in your case: "11,22,33") and then parse this CSV in Javascript inside the "TestRest" service.
Let me know if this helps?
Unfortunately the body must be in json format
Hi Matt Lang
In the 'TestRest' service add an input parameter of JSON type. Set this input parameter to equal to the var variable. Now iterate this var variable to access key and values of your message.
for example,
say In 'TestRest' service name of input parameter is JSONInput, i.e. of json type.
now write script as following:
var my_json = JSONInput;
for (var k in my_json) {
logger.warn("key : " + k + " - value : " + my_json
}
Please let me know if it is unclear and I can try to clarify it for you!
Thanks,
Meenakshi
Hi Meenakshi, it looks like the JSONInput comes in as 'undefined' with that code. I still have the body set to {"Value1":11,"Value2":22,"Value3":33}
I'm using Hurl.it to test the REST requests.