Call SOAP request operation in Node.js

1.3k Views Asked by At

I'm trying to make a SOAP request using node-soap - I can successful create a client but when I try to call the operation defined in the WSDL it returns undefined? Is this how I correctly call an operation?

const soap = require('soap');
const btoa = require('btoa');

response = {}
exports.getInventory = async (event, context) => {

    let username = '******';
    let password = '**********';

    let wsdlUrl = 'https://webservices.onewaybike.nl/CubeServices.svc?wsdl';

    const security = new soap.BasicAuthSecurity(username, password);

    let client = await soap.createClientAsync(wsdlUrl);
    client.setSecurity(security)
    
    let args = { Year: 2020}

    let dataResponse = await client.GetStockInfoNewOrdersForSeason(args)
    console.log(dataResponse)

    response = {
        statusCode: 200,
        body: "Inventory retrieved."
    };

    return response;
}
1

There are 1 best solutions below

0
Ado On BEST ANSWER

You have to use the Async Method.
Append Async to the method GetStockInfoNewOrdersForSeasonAsync

let [dataResponse] = await client.GetStockInfoNewOrdersForSeasonAsync(args)

The response is an Array. From the npm soap documentation :

Client.methodAsync(args, options) - call method on the SOAP service.

 client.MyFunctionAsync({name: 'value'}).then((result) => {
   // result is a javascript array containing result, rawResponse, soapheader, and rawRequest
   // result is a javascript object
   // rawResponse is the raw xml response string
   // soapHeader is the response soap header as a javascript object
   // rawRequest is the raw xml request string
 })