Member-only story
How to Perform SOAP Requests With Node.js
For when you aren’t able to use REST

What is SOAP?
SOAP stands for Simple Object Access Protocol. It’s basically the only thing that existed before REST. It’s an XML based API…before going any further, know that REST is much, MUCH better.
A SOAP server consists of something called a WSDL (Web Services Description Language) which contains an XML schema to define what actions can be sent to the server. Think of the REST API docs.
How to Consume a SOAP Service?
After about an hour or two of browsing the web for a SOAP service that still worked, I finally found one. Luckily, NOAA still has some functioning legacy tech which uses SOAP.
To hit a SOAP API, you need to send a POST request containing a couple of things:
- The right headers (usually two)
- A SOAP envelope
Headers
For almost all SOAP requests, you need to send the data in XML format:
Content-Type: text/xml;charset=UTF-8
Another header you will need to send will be the soapAction
. Now, not all services require a soapAction
(if the WSDL says soapAction=""
), but if the SOAP service provides multiple functions, you’ll usually need to send it. The way you find the soapAction
will be to “ctrl+f” the WSDL or rely on API docs if they exist, which are hard to find in my opinion since SOAP is pretty dated. Here’s the WSDL I’ll be testing provided by NOAA.
Here’s an example soapAction
for the above-mentioned WSDL:
soapAction:'https://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl#LatLonListZipCode'
To conclude, we will at minimum need those two headers, but you may also want to add a third to be friendly to some external web services that require a user-agent. For example:
user-agent: "Mozilla/5.0 (Macintosh…