Original Message:
Sent: Tue November 11, 2025 05:23 AM
From: Basma Hesham
Subject: How to parse SOAP Response in API Connect gateway script
Hi Steve,
Thanks for your support.
Would you mind to have a quick call to try this ? it'd be very appreciated.
------------------------------
Basma Hesham
Original Message:
Sent: Sat November 08, 2025 01:10 PM
From: Steve Linn
Subject: How to parse SOAP Response in API Connect gateway script
Hi Basma,
As I don't have an environment anymore to play around to test out your use case, I'd suggest you open a PMR on this one.
Best of luck!
Steve
------------------------------
Steve Linn
Senior Consulting I/T Specialist
IBM Retired
Original Message:
Sent: Thu November 06, 2025 05:50 AM
From: Basma Hesham
Subject: How to parse SOAP Response in API Connect gateway script
Hi Stieve,
We are currently facing a challenge in exposing a SOAP service through IBM API Connect. The WSDL and its associated XSDs have been successfully deployed to the API Manager. However, when attempting to access the service via the browser using the ?wsdl query parameter, the returned WSDL reference points to a generic endpoint without a unique identifier URI.
π Observed Behavior:
Accessing the WSDL via the browser (e.g., https://apic-1-gw-gateway-cp4i-dev.apps.cloudpak-ocp-nonprod.XXXXX.com/XXX-dev/$catalog_name/?wsdl) returns a fixed reference to one specific WSDL.
The returned WSDL contains a generic service endpoint without a unique path or identifier, making it difficult to distinguish between services.
Attempts to manually update the service tag in the WSDL with a specific path were unsuccessful-the reference still resolves to the generic endpoint.
Suspected caching issue: republishing the APIs under different products did not resolve the behavior.
This issue affects approximately 40 SOAP APIs.
β Request for Guidance:
Is there a recommended approach to ensure each SOAP service exposes a unique URI in the WSDL reference?
Can this issue be tested and resolved by updating one or two APIs first, or is it necessary to update all 40 APIs to observe the effect?
Are there any known caching mechanisms or configuration steps in API Connect that could be influencing this behavior?
π Additional Notes:
We are looking for a scalable and maintainable solution that allows proper exposure of each SOAP service with a distinct endpoint. Any best practices or configuration tips would be greatly appreciated.
------------------------------
Basma Hesham
Original Message:
Sent: Mon March 13, 2023 02:24 PM
From: Steve Linn
Subject: How to parse SOAP Response in API Connect gateway script
Hi Ashok,
You you should check each value before continuing to use it, and that would include the consentID element. The item(0) function would return an undefined for an empty nodeset, so you should ensure that the element exists before attempting to search inside of it or as is the case with the CONSENT_ID element, before pulling the text content.
var consentID;var soapBody = body.getElementsByTagNameNS("http://schemas.xmlsoap.org/soap/envelope/", "Body").item(0);if (soapBody !== undefined) { var gcResponse = soapBody.getElementsByTagNameNS("http://www.infosys.com/response/GetConsent","GetConsentResponse").item(0); if (gcResponse !== undefined) { var consentIDElement = gcResponse.getElementsByTagNameNS("http://www.infosys.com/response/GetConsent", "CONSENT_ID").item(0); if (consentIDElement !== undefined) { consentID = consentIDElement.textContent; } }}
Best Regards,
Steve
------------------------------
Steve Linn
Senior Consulting I/T Specialist
IBM
Original Message:
Sent: Mon March 13, 2023 12:25 PM
From: Ashok Beshra
Subject: How to parse SOAP Response in API Connect gateway script
Hi Steve...
Thanks for your valuable feedback on this. I will try the above code and see if it works. As per your advice can I try the below code to get the value of fields from SOAP response? Please suggest. Thanks
var soapBody = body.getElementsByTagNameNS("http://schemas.xmlsoap.org/soap/envelope/", "Body").item(0);
var gcResponse = soapBody.getElementsByTagNameNS("http://www.infosys.com/response/GetConsent","GetConsentResponse").item(0);
var consentID = gcResponse.getElementsByTagNameNS("http://www.infosys.com/response/GetConsent", "CONSENT_ID").item(0).textContent;
------------------------------
Ashok Beshra
Original Message:
Sent: Mon March 13, 2023 08:57 AM
From: Steve Linn
Subject: How to parse SOAP Response in API Connect gateway script
Hi Ashok,
You need to use the getElementsByTagNameNS function when working with an element that has a namespace uri associated with it. The getElementsByTagName should only be used when the element does not have a namespace uri associated with it. Please try
var consentID = body.getElementsByTagNameNS("http://schemas.xmlsoap.org/soap/envelope/", "Body").item(0).getElementsByTagNameNS("http://www.infosys.com/response/GetConsent","GetConsentResponse").item(0).getElementsByTagNameNS("http://www.infosys.com/response/GetConsent", "CONSENT_ID").item(0).textContent;
One other word of advice is that you should break this statement up into multiple statements otherwise you could get back an empty nodelist where item(0) is undefined. Then the following getElementsByTagNameNS will throw an exception, something like getElementByTagNameNS does not exist on undefined.
Best Regards,
Steve
------------------------------
Steve Linn
Senior Consulting I/T Specialist
IBM
Original Message:
Sent: Mon March 13, 2023 06:59 AM
From: Ashok Beshra
Subject: How to parse SOAP Response in API Connect gateway script
Hi All...
I am trying to parse the SOAP response in API Connect(10.0.5.2) assembly using (Gateway script) and get the value of SOAP field in variable(consentID) and set it in API HTTP response, but I am not able to parse the SOAP response fields. Please help on implementing the same in Gateway script.
SOAP Response
=============
<soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 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>
<NS1:GetConsentResponse xmlns:NS1="http://www.infosys.com/response/GetConsent">
<NS1:CONSENT_ID>12345</NS1:CONSENT_ID>
<NS1:CONSENT_EXPIRY>2023-03-09T12:25:31.298286</NS1:CONSENT_EXPIRY>
</NS1:GetConsentResponse>
</soapenv:Body>
</soapenv:Envelope>
Gateway script code
===================
var apim = require('apim');
var body = apim.getvariable('request.body');
var xmlString = XML.stringify(body);
console.error("Root", xmlString);
var domTree = undefined;
try {
// use XML.parse() to parse the xmlString into a DOM tree structure
domTree = XML.parse(xmlString);
} catch (error) {
// there was an error while parsing the XML string
console.error('error parsing XML string ' + error);
throw error;
}
var transform = require('transform');
var consentID = body.getElementsByTagName("Body").item(0).getElementsByTagName("GetConsentResponse").item(0).getElementsByTagName("CONSENT_ID").item(0).textContent;
//var consentID = '12345';
var consentExpiry = '12345';
var metadata = {"CONSENT_ID": consentID};
var resp_string = JSON.stringify (metadata);
context.message.statusCode = '200 Wonderful';
apim.setvariable('message.headers.X-API-OAUTH-METADATA-FOR-ACCESSTOKEN', resp_string, 'set');
apim.setvariable('message.headers.X-API-OAUTH-METADATA-FOR-PAYLOAD', resp_string, 'set');
------------------------------
Ashok Beshra
------------------------------