Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X
Here is how you can do this....
ThingWorx has ContentLoaderFunctions API which provides services to load or post content to and from other web applications. One can issue an HTTP request using any of the allowed actions (GET, POST, PUT, DELETE).
List of available ContentLoaderFunctions:
Delete
GetCookies
GetJSON
GetText
GetXML
LoadBinary
LoadImage
LoadJSON
LoadMediaEntity
LoadText
LoadXML
PostBinary
PostImage
PostJSON
PostMultipart
PostText
PostXML
PutBinary
PutJSON
PutText
PutXML
Example:
var params = {
var content = "<xml><tag1>NAME</tag1><tag2>AGE</tag2></xml>";
var params = {
url: "http://localhost/Thingworx/Things/thingName/Services/serviceName?postParameter=parameterName" /* STRING */,
content: content /* STRING */,
password: "admin" /* STRING */,
username: "Administrator" /* STRING */
};
var result = Resources["ContentLoaderFunctions"].PostXML(params);
Hi Experts,
Just a quick help.
I'm sending a POST request from TW to external SAP system gateway service.
It failed due to CSRF token authentication.
The solution is to send a GET request to the odata service and persist the XCSRF token value in a variable and pass it to the POST request header. Can someone tell a simple solution or the code snippet structure.
Appreciate your help.
Hi Ankit,
LoadXML throws below error whenever try to execute it.
Message :: The markup in the document following the root element must be well-formed. - See Script Error Log for more details.
Below is my snippet.
var params = {
proxyScheme: undefined /* STRING */,
headers: {'userName':'testUser','token':'f7bbddf5-b139-4981-bf62-5fc2b3e5dfb2','classDate':'2019-01-25 14:12:20'} /* JSON */,
ignoreSSLErrors: undefined /* BOOLEAN */,
useNTLM: undefined /* BOOLEAN */,
workstation: undefined /* STRING */,
useProxy: undefined /* BOOLEAN */,
withCookies: undefined /* BOOLEAN */,
proxyHost: undefined /* STRING */,
url: 'http://10.10.268.35:8080/MyserviceWF/api/classLogin' /* STRING */,
timeout: undefined /* NUMBER */,
proxyPort: undefined /* INTEGER */,
password: undefined /* STRING */,
domain: undefined /* STRING */,
username: undefined /* STRING */
};
// result: XML
var result = Resources["ContentLoaderFunctions"].LoadXML(params);
Please correct,if required.
There issue appears to be not with your code but with the response your got that is not properly formatted XML document that is expected and can't be parsed. You may want to try using LoadText instead of LoadXML and examine the response to see if it is XML formatted or possibly in JSON or some other format.
You can find more information about ContentLoader class used in ContentLoaderFunctions in JavaDoc at http://support.ptc.com/help/thingworx_hc/javadoc/com/thingworx/resources/content/ContentLoader.html