Skip to content

Can Postman Be Used For Soap Api

API Testing Blog

Can Postman Be Used for SOAP API Testing?

While Postman is primarily known for its REST API testing capabilities, it can also be used effectively for testing SOAP APIs. Here’s a comprehensive guide exploring how to leverage Postman for SOAP API testing, along with practical examples and step-by-step instructions.

Understanding SOAP APIs and Their Differences from REST

SOAP (Simple Object Access Protocol) is a protocol used for exchanging structured information over the internet, primarily used in enterprise applications. It utilizes XML for data exchange and relies on the HTTP protocol for communication. Unlike REST APIs, which typically employ JSON for data transfer, SOAP APIs rely on XML for both requests and responses.

Setting Up a SOAP Request in Postman

  1. Create a New Request: Open Postman and create a new request.

  2. Choose the HTTP Method: Typically, SOAP APIs utilize the POST method for requests.

  3. Specify the URL: Enter the endpoint URL of your SOAP API.

  4. Select the Body Type: Choose raw as the body type.

  5. Specify the Content Type: Set the content type to application/soap+xml.

  6. Compose the SOAP Envelope: Construct the SOAP envelope within the raw body. This structure includes:

    • Envelope: Contains the overall request structure.
    • Header: Includes optional authentication details or other metadata.
    • Body: Encapsulates the actual request data.

Sample SOAP Request (XML):

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:GetWeatherData>
<tem:zipCode>90210</tem:zipCode>
</tem:GetWeatherData>
</soapenv:Body>
</soapenv:Envelope>

Executing and Verifying the SOAP Request

  1. Send the Request: Click the “Send” button to submit your SOAP request.

  2. Inspect the Response: Postman will display the response from the API. Since SOAP APIs utilize XML, the response will also be in XML format.

  3. Verify Response Data: Examine the response XML to ensure the expected data is present and the request was processed correctly.

Enhancing SOAP API Testing with Postman

1. Using SOAP Request Builder: Postman offers a built-in SOAP Request Builder that can help generate the XML envelope for your request.

2. Request Chaining: Employ Postman’s request chaining feature to test complex workflows involving multiple SOAP API calls.

3. Utilizing Environment Variables: Store sensitive information like API keys and URLs in environment variables for improved security and reusability.

4. Creating Test Suites: Organize multiple SOAP API tests into test suites for efficient and organized testing.

5. Integrating with CI/CD Pipelines: Integrate Postman with continuous integration and continuous delivery processes to automate SOAP API testing within your development pipeline.

Example: Testing a Weather API using Postman

// Sample SOAP Request for a weather API
const request = {
"method": "POST",
"url": "http://www.webservicex.net/globalweather.asmx",
"header": {
"Content-Type": "application/soap+xml; charset=utf-8",
"SOAPAction": "http://www.webservicex.net/GetWeather"
},
"body": {
"mode": "raw",
"raw": "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:web=\"http://www.webservicex.net\"><soapenv:Header/><soapenv:Body><web:GetWeather><web:CityName>London</web:CityName></web:GetWeather></soapenv:Body></soapenv:Envelope>"
}
};
// Send the request
pm.sendRequest(request, function (err, res) {
if (err) {
console.log(err);
} else {
// Parse the XML response
const responseXml = pm.response.text();
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(responseXml, "text/xml");
// Extract the temperature from the response
const temperature = xmlDoc.getElementsByTagName("Temperature")[0].textContent;
// Validate the response
pm.test("Temperature should be a number", function () {
pm.expect(parseFloat(temperature)).to.be.a("number");
});
console.log("Weather in London:", temperature);
}
});

Conclusion

Postman, despite primarily being associated with REST API testing, can seamlessly accommodate testing SOAP APIs. By understanding SOAP API principles and utilizing Postman’s features effectively, you can efficiently test these APIs and ensure the quality of your software applications.

API Testing Blog