Is there any examples of how to do a SOAP call with node.js in Switch?
I can't find any information about how you do this with node.js, only the old SOAP class for the old scripting environment.
I am completely new to node.js, but thought I should start learning with this specific task.
SOAP call with node.js
- billy.olvestad
- Member
- Posts: 54
- Joined: Mon Nov 19, 2018 10:08 pm
- Location: Sweden
- Contact:
Re: SOAP call with node.js
The easiest option will be to use one of the npm packages for this.
https://www.npmjs.com/search?q=soap
https://www.npmjs.com/search?q=soap
Laurent De Wilde, Solution Architect @ Enfocus
- billy.olvestad
- Member
- Posts: 54
- Joined: Mon Nov 19, 2018 10:08 pm
- Location: Sweden
- Contact:
Re: SOAP call with node.js
Ok. Thanks, I will have a look at it.laurentd wrote: ↑Tue Feb 22, 2022 12:05 pm The easiest option will be to use one of the npm packages for this.
https://www.npmjs.com/search?q=soap
- billy.olvestad
- Member
- Posts: 54
- Joined: Mon Nov 19, 2018 10:08 pm
- Location: Sweden
- Contact:
Re: SOAP call with node.js
I am stuck on an error in Switch when running my script. I am a beginner with node.js, so be kind to me
The code is as follows (I have replaced server names and authorization with nonsense, of course)
When I run this script, it gets to the line where i write "one" to the switch log, and then it stops. The warning I get in the switch log is as follows.
The code is as follows (I have replaced server names and authorization with nonsense, of course)
Code: Select all
async function jobArrived(s, flowElement, job) {
const soapRequest = require('easy-soap-request');
const fs = require("fs-extra");
const jobPath = await job.get(AccessLevel.ReadOnly);
const url = 'http://url_to_soap_server';
const Headers = {
'Accept-Encoding': 'gzip,deflate',
'Content-Type': 'text/xml;charset=UTF-8',
'SOAPAction': 'soap-action',
'Authorization': 'Basic bXlVc2VyOm15UGFzc3dvcmQK',
'Content-Length': '1643',
'Host': 'host-address',
'Connection': 'Keep-Alive',
'User-Agent': 'Apache-HttpClient/4.5.5 (Java/16.0.1)',
};
const xml = await fs.readFile(jobPath, { encoding: "utf8" });
await job.log(LogLevel.Info, xml, 'xmltext');
(async () => {
await job.log(LogLevel.Info, 'one'); //Just to see how far we get
const { response } = await soapRequest({ url: url, headers: Headers, xml: xml, timeout: 3000 });
await job.log(LogLevel.Info, 'two'); //Just to see how far we get
const { headers, body, statusCode } = response;
await job.log(LogLevel.Info, 'three'); //Just to see how far we get
await job.setPrivateData('headers: ', headers);
await job.setPrivateData('body: ', body);
await job.setPrivateData('statusCode: ', statusCode);
})();
const jobname = await job.getName(true);
await job.sendToSingle(jobname);
}
I can't figure out what I have done wrong. Can anyone catch my mistake?The script execution has ended while an async function or callback in the script might not have finished yet. Please check the script code for unresolved promises or missing await statements.
- billy.olvestad
- Member
- Posts: 54
- Joined: Mon Nov 19, 2018 10:08 pm
- Location: Sweden
- Contact:
Re: SOAP call with node.js
It seems like something goes wrong at line 25, and the node.js step locks up, but the job goes on in the flow. I can't stop the flow before i have force quit the node.js service.
Up until that line everything executes properly.
There is an await statement on that line, so I don´t know why it doesn´t wait.
Up until that line everything executes properly.
There is an await statement on that line, so I don´t know why it doesn´t wait.
Re: SOAP call with node.js
You have a self executing function halfway your script. That doesn't look right, can you try this?
(Loading modules is almost always done outside your jobArrived, so I also fixed that)
(Loading modules is almost always done outside your jobArrived, so I also fixed that)
Code: Select all
const soapRequest = require('easy-soap-request');
const fs = require("fs-extra");
async function jobArrived(s, flowElement, job) {
const jobPath = await job.get(AccessLevel.ReadOnly);
const url = 'http://url_to_soap_server';
const Headers = {
'Accept-Encoding': 'gzip,deflate',
'Content-Type': 'text/xml;charset=UTF-8',
'SOAPAction': 'soap-action',
'Authorization': 'Basic bXlVc2VyOm15UGFzc3dvcmQK',
'Content-Length': '1643',
'Host': 'host-address',
'Connection': 'Keep-Alive',
'User-Agent': 'Apache-HttpClient/4.5.5 (Java/16.0.1)',
};
const xml = await fs.readFile(jobPath, { encoding: "utf8" });
await job.log(LogLevel.Info, xml, 'xmltext');
await job.log(LogLevel.Info, 'one'); //Just to see how far we get
const { response } = await soapRequest({ url: url, headers: Headers, xml: xml, timeout: 3000 });
await job.log(LogLevel.Info, 'two'); //Just to see how far we get
const { headers, body, statusCode } = response;
await job.log(LogLevel.Info, 'three'); //Just to see how far we get
await job.setPrivateData('headers: ', headers);
await job.setPrivateData('body: ', body);
await job.setPrivateData('statusCode: ', statusCode);
const jobname = await job.getName(true);
await job.sendToSingle(jobname);
}
- billy.olvestad
- Member
- Posts: 54
- Joined: Mon Nov 19, 2018 10:08 pm
- Location: Sweden
- Contact:
Re: SOAP call with node.js
Ok, I made the changes, and now it is reporting another error:
It still executes the log of the word "one" to the switch log, so up until then it seems to executeActions with jobs can not be performed inside a 'jobArrived' entry point
- billy.olvestad
- Member
- Posts: 54
- Joined: Mon Nov 19, 2018 10:08 pm
- Location: Sweden
- Contact:
Re: SOAP call with node.js
I have tried to solve this problem, but no matter what I do the execution stops at this line
The error, or rather warning I get (yellow colour in the messages window) is:
Code: Select all
const { response } = await soapRequest({ url: url, headers: Headers, xml: xml, timeout: 3000 });
And nothing else executes after that.Actions with jobs can not be performed inside a 'jobArrived' entry point
- billy.olvestad
- Member
- Posts: 54
- Joined: Mon Nov 19, 2018 10:08 pm
- Location: Sweden
- Contact:
Re: SOAP call with node.js
I gave up.
I tried two different soap client libraries for node.js, but both of them had some sort of problem that prevented them from getting a response from this specific soap server, and other libraries were just too complicated to use for me.
I found that you can do a soap request with powershell instead, and created a batch file that calls powershell and makes the request.
That finally worked and solved my problem.
I tried two different soap client libraries for node.js, but both of them had some sort of problem that prevented them from getting a response from this specific soap server, and other libraries were just too complicated to use for me.
I found that you can do a soap request with powershell instead, and created a batch file that calls powershell and makes the request.
That finally worked and solved my problem.