Making SOAP requests
Example
// We make use of the following public API
// https://documenter.getpostman.com/view/8854915/Szf26WHn
const { input } = args;
const url = "https://www.dataaccess.com/webservicesserver/NumberConversion.wso";
// The request body
const body = `<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<NumberToWords xmlns="http://www.dataaccess.com/webservicesserver/">
<ubiNum>${input}</ubiNum>
</NumberToWords>
</soap:Body>
</soap:Envelope>
`;
const headers = {
// Additional headers may be required
// dpending on your server implementation
"Content-Type": "text/xml; charset=utf-8",
};
const options = { method: "POST", headers, body };
const chatlayer = ChatlayerResponseBuilder();
try {
// Perform the request to the SOAP api
const response = await fetch(url, options);
// Extract the text value from the response
const xmlResponse = await response.text();
// Build and match the RegExp to extract data from the response
const regExp = new RegExp(
"<m:NumberToWordsResult>(.*?)</m:NumberToWordsResult>"
);
const match = xmlResponse.match(regExp);
if (!match) {
throw new Error("Could not find the given number");
}
const result = match[1];
chatlayer.addMessage(result);
} catch (ex) {
chatlayer.addMessage(ex.toString());
} finally {
chatlayer.send();
}Last updated
Was this helpful?