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

Community Tip - You can change your system assigned username to something more personal in your community settings. X

ThingWorx problem passing XML as a service parameter from one script to another

asinclair
12-Amethyst

ThingWorx problem passing XML as a service parameter from one script to another

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?

ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

3 REPLIES 3

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

Announcements


Top Tags