Test XML and SOAP APIs with a modern API client
Banks, payment processors, logistics carriers and government services still run on XML, often SOAP. You can test them with the same collections, environments and CI setup as your JSON APIs. The request is plain HTTP; only the body and the checks look different.
A SOAP request
POST {{soapUrl}}
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://example.com/stock/GetQuote"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:s="http://example.com/stock">
<soap:Body>
<s:GetQuote>
<s:Symbol>{{symbol}}</s:Symbol>
</s:GetQuote>
</soap:Body>
</soap:Envelope>In the Body tab, pick the raw mode and paste the envelope. {{variables}} work inside XML like anywhere else. Replace the default Content-Type: application/json header with the XML one.
For SOAP 1.2 the action moves into the content type: Content-Type: application/soap+xml; charset=utf-8; action="http://example.com/stock/GetQuote", and the envelope namespace is http://www.w3.org/2003/05/soap-envelope.
If the service has a WSDL, open it in a browser: each operation lists its soapAction and the shape of its input message.
Checks without code
On the request's Tests tab:
| Source | Path | Operator | Expected |
|---|---|---|---|
| Status code | equals | 200 | |
| Header | Content-Type | contains | xml |
| Body | does not contain | Fault> | |
| Body | matches regex | <(\w+:)?Price>\d+\.\d{2}</ |
Fault> matches both <soap:Fault> and <Fault> whatever the prefix. The regex allows any namespace prefix on Price.
Reading values with a script
There's no XML parser in the script runtime, but SOAP responses are regular enough for a small helper that ignores namespace prefixes:
function xmlValue(xml, tag) {
const m = new RegExp(`<(?:\\w+:)?${tag}(?:\\s[^>]*)?>([\\s\\S]*?)</(?:\\w+:)?${tag}>`).exec(xml);
return m ? m[1].trim() : undefined;
}
const xml = pm.response.text();
const price = xmlValue(xml, 'Price');
pm.test('has a price', () => pm.expect(price).to.match(/^\d+\.\d{2}$/));
pm.environment.set('lastPrice', price);That's enough to pass a session id or an order number to the next request. It isn't a full XML parser: it doesn't handle CDATA or repeated elements of the same name. For a list, use a global regex and matchAll.
SOAP faults
A SOAP fault is the protocol's error, with a code and a message:
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Unknown symbol</faultstring>
</soap:Fault>SOAP 1.1 services send faults with HTTP 500, so a status check alone can't tell a fault from a crash. For negative tests, check the fault itself:
pm.test('unknown symbol is a client fault', () => {
const xml = pm.response.text();
pm.expect(xmlValue(xml, 'faultcode')).to.include('Client');
pm.expect(xmlValue(xml, 'faultstring')).to.include('Unknown symbol');
});Plain XML APIs
Non-SOAP XML APIs work the same, minus the envelope: Content-Type: application/xml, and Accept: application/xml if the API can answer JSON too. The checks above apply unchanged.
WS-Security and certificates
Many SOAP services require a client certificate (see mutual TLS) or a WS-Security header with a username token in the envelope. The header is just more XML, so keep the password in a secret environment variable and reference it as {{wsPassword}}. Signed WS-Security messages (XML signatures) can't be produced by the script runtime; test those services through a test endpoint that accepts unsigned messages, or with the vendor's tool.
Run it in CI
Nothing changes:
requestarium run-collection "Carrier SOAP API" --env Sandbox --junit soap.xml