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

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

SOAP Request from Thingworx to external app

AndyHilton
13-Aquamarine

SOAP Request from Thingworx to external app

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.

 

 

ACCEPTED SOLUTION

Accepted Solutions
AndyHilton
13-Aquamarine
(To:slangley)

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;

 

View solution in original post

6 REPLIES 6
PaiChung
22-Sapphire I
(To:AndyHilton)

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

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.

slangley
23-Emerald II
(To:AndyHilton)

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

PaiChung
22-Sapphire I
(To:slangley)

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.

AndyHilton
13-Aquamarine
(To:slangley)

Hey everyone,

 

Apologies for the late reply.  I get the following XML response from resultXML in Thingworx where xxxxxxxx is the server address of my Pavilion 8 instance.

<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" headers="" responseHeaders="Server=Apache-Coyote/1.1Set-Cookie=JSESSIONID=B540CEC8FCAC7369323EBCB2C760EDB8; Path=/; HttpOnlyContent-Type=text/xml;charset=utf-8Transfer-Encoding=chunkedVary=Accept-EncodingDate=Thu, 15 Jun 2023 16:43:19 GMTConnection=close" responseStatus="protocolVersion=HTTP/1.1:statusCode=500:reasonPhrase=Internal Server Error">
 <soapenv:Body>
  <soapenv:Fault>
   <faultcode xmlns:ns1="http://xml.apache.org/axis/">ns1:Client.NoSOAPAction</faultcode>
   <faultstring>no SOAPAction header!</faultstring>
   <detail>
    <ns2:hostname xmlns:ns2="http://xml.apache.org/axis/">xxxxxxxx</ns2:hostname>
   </detail>
  </soapenv:Fault>
 </soapenv:Body>
</soapenv:Envelope>

 I'm assuming this means I need a specific header by not sure how I would format it or what properties I would put in that SOAPAction header.

AndyHilton
13-Aquamarine
(To:slangley)

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;

 

Announcements


Top Tags