Skip to content

Instantly share code, notes, and snippets.

@circa10a
Last active March 19, 2021 02:42
Show Gist options
  • Save circa10a/f6f7c9d8d5e4118e6cf2202262b2fddf to your computer and use it in GitHub Desktop.
Save circa10a/f6f7c9d8d5e4118e6cf2202262b2fddf to your computer and use it in GitHub Desktop.
const soapRequest = require('easy-soap-request');
const fs = require('fs');
// example data
const url = 'https://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php';
const sampleHeaders = {
'user-agent': 'sampleTest',
'Content-Type': 'text/xml;charset=UTF-8',
'soapAction': 'https://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl#LatLonListZipCode',
};
const xml = fs.readFileSync('test/zipCodeEnvelope.xml', 'utf-8');
// usage of module
(async () => {
const { response } = await soapRequest({ url: url, headers: sampleHeaders, xml: xml, timeout: 1000 }); // Optional timeout parameter(milliseconds)
const { headers, body, statusCode } = response;
console.log(headers);
console.log(body);
console.log(statusCode);
})();
@circa10a
Copy link
Author

@talesmgodois
Copy link

How could I get a parsed version of the xml?

@circa10a
Copy link
Author

@talesmgodois I've had success with xml2js

@harishpatha
Copy link

How to handle the security here?

@salokod
Copy link

salokod commented Mar 17, 2021

I'm getting a http 405 method not allowed - any idea?

@circa10a
Copy link
Author

@salokod maybe the server you are hitting doesn't allow POST requests? Perhaps PUTS?

@salokod
Copy link

salokod commented Mar 18, 2021

allow: 'GET,OPTIONS',
'content-type': 'application/json',
'content-length': '52'
},

is part of the response, does that mean I have to use a GET command? Can I do so with this easy-soap-request?

@circa10a
Copy link
Author

@salokod yes, you can pass the method option like so as of version 4.1.3

 await soapRequest({ method: 'GET',  url, headers, data: <some json or xml> });

@salokod
Copy link

salokod commented Mar 19, 2021

I keep getting the WSDL definition back:

















<soap:binding style='document' transport='http://schemas.xmlsoap.org/soap/http'></soap:binding>

<soap:operation soapAction='https://my-server.com:8482/ws/GetJob'></soap:operation>

<soap:body use='literal'></soap:body>


<soap:body use='literal'></soap:body>





<soap:address location='https://my-server.com:8482/ws/GetJob'></soap:address>


text/xml, text/html, image/gif, image/jpeg, *; q=.2, /; q=.2

Any idea what I could be doing wrong? It's driving me nuts. I got the SOAP envelope from SOAP UI - here is the example:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://www.northgate-is.com/proiv/webservices/types">
soapenv:Header/
soapenv:Body
typ:GetJob
<Authorization_ID>AUTHID</Authorization_ID>
</typ:GetJob>
</soapenv:Body>
</soapenv:Envelope>

@circa10a
Copy link
Author

circa10a commented Mar 19, 2021

That's what I would expect from a GET request. You need to hit the /GetJob endpoint I suspect. But I know nothing of this API. You would need to consult the maintainer or check for API consumption documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment