Skip to main content
13-Aquamarine
May 30, 2023
Solved

SOAP Request from Thingworx to external app

  • May 30, 2023
  • 3 replies
  • 2005 views

I am sending a SOAP Request from Thingworx to FactoryTalk Pavilion 8.  I run the following script but get nothing back.  The ldp in the code below is a tag whose value the SOAP call is supposed to retrieve.  Thingworx 9.3

 

var content ='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\
<soapenv:Body>\
<getTimeSeries>\
<ldps>\
<ldp>MAIN/Line1APQC/L1_QualityCtrl_KPIs/CV___Peel/data::output/Utilization/UnitUptime</ldp>\
</ldps>\
<starttime>2023-01-06T20:45:00</starttime>\
<endtime>2023-05-26T00:10:00</endtime>\
</getTimeSeries>\
</soapenv:Body>\
</soapenv:Envelope>';

 

var resultXML = Resources["ContentLoaderFunctions"].PostXML({
url: "http://xxxxxxxx/integration/services/TimeSeriesPagingService" /* STRING */,
content: content,
password: 'xxxx' /* STRING */,
username: 'xxxx' /* STRING */
});

 

var data = resultXML.*::Body.*::getTimeSeriesResponse.*::rows.*;   //See Postman results below.
.....

Some code to put in a table.

......

 

The result I get back in Postman looks like the following:

 

<?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Body>
        <getTimeSeriesResponse endtime="2023-05-26T00:10:00.0Z" starttime="2023-01-06T20:45:00.0Z">
            <nextpagestarttimes>
                <querybookmark ldp="MAIN/Line1APQC/L1_QualityCtrl_KPIs/CV___Peel/data::output/Utilization/UnitUptime" pagestarttime="2023-01-07T16:00:00.0Z"/>
            </nextpagestarttimes>
            <cols>
                <col datatype="Real" desc="MAIN/Line1APQC/L1_QualityCtrl_KPIs/CV___Peel/data::output/Utilization/UnitUptime" id="C0" isdiscrete="true"/>
            </cols>
            <rows>
                <row time="2023-01-06T20:59:59.999Z">
                    <cell id="C0">100.0</cell>
                </row>
            </rows>
        </getTimeSeriesResponse>
    </soapenv:Body>
</soapenv:Envelope>
 
1. Is this the correct way to send a SOAP Request to another application with Basic Authentication?  I think the resultXML varible is correct but really have no idea.  I would assume I should get something back given that Postman returns a good result with data for the timeframe in question.

 

 

Best answer by AndyHilton

I just figured it out with the following.  Adding the header variable and then assigning that variable to the headers field in resultXML.  See bold below:

 

var content ='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\
<soapenv:Body>\
<getTimeSeries>\
<ldps>\
<ldp>MAIN/Line1APQC/L1_QualityCtrl_KPIs/CV___Peel/data::output/Utilization/UnitUptime</ldp>\
</ldps>\
<starttime>2023-01-06T20:45:00</starttime>\
<endtime>2023-05-26T00:10:00</endtime>\
</getTimeSeries>\
</soapenv:Body>\
</soapenv:Envelope>';
var headers = {"Content-Type": "text/xml","SOAPAction":"http://xxxxxxxxxx/integration/services/TimeSeriesPagingService"};

 

var resultXML = Resources["ContentLoaderFunctions"].PostXML({
headers: headers,
url: "http://xxxxxxxx/integration/services/TimeSeriesPagingService" /* STRING */,
content: content,
password: 'xxxxx' /* STRING */,
username: 'xxxxx' /* STRING */
});


result = resultXML;

 

3 replies

22-Sapphire I
May 31, 2023

Don't have an answer but have you searched the community? There are quite a few posts around SOAP calls.

16-Pearl
June 2, 2023

What is the content of 'resultXML' after the request was sent? This should hold the content you also receive via postman but you did not say what it actually is.

Community Manager
June 7, 2023

Hi @AndyHilton.

 

Are getting a response to this statement?

 

var resultXML = Resources["ContentLoaderFunctions"].PostXML({

 

For troubleshooting, you can change "resultXML" to "result" and comment out the rest of the code to see if you get any results back.  That will give you some idea of how to proceed for resolving the issue.

 

Let us know and we'll be happy to assist further.

 

Regards.

 

--Sharon

22-Sapphire I
June 8, 2023

You can also set the output to string after setting it to Result to see the 'raw' return, potentially if it can't be interpreted.