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
The first script peeks into the XML - a parameter of an HTTP POST service request (REST API) - to identify the thing and service that needs to be invoked to parse out the data. Then the script calls the second service passing the same XML object as the first and only parameter.
ThingWorx throws the following exception (that is returned in the payload of HTTP 500 Internal Server Error).
Wrapped java.lang.Exception: Invalid parameter type for service
Now what? Is this just not allowed or is the XML object in some state where it cannot be used in another script?
Solved! Go to Solution.
The parameter needs to be wrapped in a params structure. This is just a silly newbie mistake.
Replace this ...
var eventInfoTable = Things[powerSourceThingName].GetRawEvents(XMLPayload);
With this ...
var params {
XMLPayload: XMLPayload
};
var eventInfoTable = Things[powerSourceThingName].GetRawEvents(params);
I was able to isolate the call to the send script in a copy of the first script ... no exceptions are thrown other than Wrapped java.lang.Exception: Invalid parameter type for service
// XMLPayload sent from PostMan is: <events key="6413920120520232">...</events>
var powerSourceThingName = "CP_PowerSource.76.53";
if (Things[powerSourceThingName] == undefined)
throw new Exception("Thing does not exist: " + powerSourceThingName);
if (Things[powerSourceThingName].GetRawEvents == undefined)
throw new Exception("GetRawEvents service does not exist in " + powerSourceThingName);
if (XMLPayload == undefined)
throw new Exception("XMLPayload is undefined");
if (XMLPayload.events == undefined)
throw new Exception("Cannot find the <events> element in XMLPayload");
var eventInfoTable = Things[powerSourceThingName].GetRawEvents(XMLPayload);
oops .. use throw new Error() in place of throw new Exception(). But the outcome is the same.
The parameter needs to be wrapped in a params structure. This is just a silly newbie mistake.
Replace this ...
var eventInfoTable = Things[powerSourceThingName].GetRawEvents(XMLPayload);
With this ...
var params {
XMLPayload: XMLPayload
};
var eventInfoTable = Things[powerSourceThingName].GetRawEvents(params);