soap client

Hello everyone,

I was wondering if anyone has had success connecting to a soap api with basic authentication in Wix?

I’ve tried WixFetchRequest but with no detailed examples i’m stumped.

I also tried the node-soap node module, however had no luck importing and using it.

And I cannot use XMLHttpRequest (‘XMLHttpRequest’ is not defined).

Any assistance in the way of some basic examples would be very much appreciated.

Thanks, Jamie

Here are some examples that use authentication:

Thanks @Yisrael, I’ve had a good read over these resources already, I think the my biggest hurdle is that this is an SOAP XML API and wix-fetch seems to be geared around more moden REST/JSON calls. I think what I need to do should be possible with wix-fetch by manually defining the header and body as part of the WixFetchRequest, however I think an example of an XML SOAP implementation would be helpful for me to see how to do this (this is my first time with SOAP). If anyone out there has done this, I would be most grateful if they would share some knowledge.

Hi Jamie,

This example uses “soap” and “xml-js” which are installable NPM modules .

import 'convert' from 'xml-js';
import 'soap' from 'soap';

function Soap(actionName, additionalArgs = {}) {
	const url = 'ENDPOINTURL';
	const args = {
		in0: SOMEID,
		in1: 'USERID',
		in2: 'TOKEN',
	};

	for (const [key, val] of Object.entries(additionalArgs)) {
		args[key] = val;
	}
	return soap.createClientAsync(url)
		.then((client) => {
			return client[actionName](args);
		})
		.then((json) => {
			try {
				json = json[0];
				json = json["out"];
				const transXml = convert.xml2js(json, { compact: true });

				return transXml;
			} catch (e) {}
			return json;
		})
		.catch(error => {
			console.log(error);
			return 'error';
		})
}

Thanks for replying Ido.

I got a little bit past this, see post here: https://www.wix.com/corvid/forum/community-discussion/wsse-soap-request-in-corvid any help appreciated.