Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node-soap - TypeError: callback is not a function

I'm receiving the following generic TypeScript error when invoking a SOAP method on a node-soap client in NodeJS. How do I fix it?

  • https://www.npmjs.com/package/soap - version: 0.35.0

Example Code

const [result] = await mySoapClient.Perform_Operation({ ... })

Error

TypeError: callback is not a function
    at /Users/nick/node_modules/soap/lib/client.js:203:17
    at parseSync (/Users/nick/node_modules/soap/lib/client.js:305:24)
    at /Users/nick/node_modules/soap/lib/client.js:466:24
    at Request._callback (/Users/nick/node_modules/soap/lib/http.js:171:17)
    at Request.self.callback (/Users/nick/node_modules/request/request.js:185:22)
    at Request.emit (events.js:223:5)
    at Request.EventEmitter.emit (domain.js:475:20)
    at Request.<anonymous> (/Users/nick/node_modules/request/request.js:1154:10)
    at Request.emit (events.js:223:5)
    at Request.EventEmitter.emit (domain.js:475:20)
    at IncomingMessage.<anonymous> (/Users/nick/node_modules/request/request.js:1076:12)
    at Object.onceWrapper (events.js:312:28)
    at IncomingMessage.emit (events.js:228:7)
    at IncomingMessage.EventEmitter.emit (domain.js:475:20)
    at endReadableNT (_stream_readable.js:1185:12)
    at processTicksAndRejections (internal/process/task_queues.js:81:21)
like image 824
Nick Grealy Avatar asked Oct 19 '25 03:10

Nick Grealy


1 Answers

The problem was node-soap has two variants of method names (that I assume it dynamically generates).

Client.method(args, callback, options) - call method on the SOAP service ** EXPECTS A CALLBACK FUNCTION **

and

Client.methodAsync(args, options) - call method on the SOAP service. ** RETURNS A PROMISE **

Obviously I was using the wrong method signature, and needed to append a Async.

i.e. Instead of...

const [result] = await mySoapClient.Perform_Operation({ ... })

I needed to append the word Async to the method. e.g.

const [result] = await mySoapClient.Perform_OperationAsync({ ... })

The mother of all gotchas.

like image 74
Nick Grealy Avatar answered Oct 20 '25 16:10

Nick Grealy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!