How to consume data with Soap and NodeJS

How to consume data with Soap and NodeJS

Recently I needed to create a microservice to consume an old API made with SOAP.

As it would just be a simple consumption and I didn't want to implement this in the core project, I decided to work with AWS Lambda. This way the endpoint would be isolated and I wouldn't need to worry about infrastructure.

The process is very simple, a single endpoint that consumes data from the soap API and returns it in a JSON.

For this scenario, I decided to use nodejs.

The first step was to find a package to work with the soap protocol, this task was very simple and I ended up using soap.

With the soap package, I managed to solve my problem basically using a single nodejs file.

// import package
const soap = require('soap')

// service endpoint
const url = ''

// create soap client
soap.createClient(url, (err, client) => {
  // call method GetUsers from soap api
      // params
      data: {
        UserId: '969666',
    function (err, result) {
      // if error
      if (err) {
        return console.log(err)

      // final result

The way the problem was solved was simple and functional, as the code was totally isolated from the main project and the best, running 100% with AWS lambdas.

Hope this helps.