Node Js prints [object Object] does not print session information - node.js

I am using the following Node Js code to use the Web service. But when I run this on Postman, I got [object Object] in console. But when I run on SoapUI, it will print the Session details
my code
router.post("/register", upload.single('image'), function (req, res, next)
{
var url = 'http://smeapps.mobitel.lk:8585/EnterpriseSMSV2/EnterpriseSMSWS?wsdl';
var session = {username: 'username', password: 'password'}
soap.createClient(url, function(err, client)
{
if(err)
console.log(err)
client.createSession(session, function(err, result)
{
console.log(result);
});
})
})
SoapUI session request
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.esms.mobitel.lk/">
<soapenv:Header/>
<soapenv:Body>
<ws:createSession>
<!--Optional:-->
<arg0>
<!--Optional:-->
<customer>12</customer>
<!--Optional:-->
<id>12</id>
<!--Optional:-->
<password>password</password>
<!--Optional:-->
<username>username</username>
</arg0>
</ws:createSession>
</soapenv:Body>
</soapenv:Envelope>
SoapUI response
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://ws.esms.mobitel.lk/">
<SOAP-ENV:Body>
<ns1:createSessionResponse>
<return>
<expiryDate>2018-10-04T06:24:25+05:30</expiryDate>
<isActive>true</isActive>
<sessionId>761033662786</sessionId>
<user>0</user>
</return>
</ns1:createSessionResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
wrap the code into try catch
Error: SOAP-ENV:Server: Procedure 'createSession' not present
{"statusCode":500,"body":"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Server</faultcode><faultstring>Procedure 'createSession' not present</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>\n","headers":{"date":"Thu, 04 Oct 2018 08:51:04 GMT","server":"Apache/2.2.15
(CentOS)","x-powered-by":"PHP/5.3.3","content-length":"304","connection":"close","content-type":"text/xml; charset=utf-8"},"request":{"uri":{"protocol":"http:","slashes":true,"auth":null,"host":"202.129.232.190:8585","port":"8585","hostname":"202.129.232.190","hash":null,"search":null,"query":null,"pathname":"/EnterpriseSMSV2/EnterpriseSMSWS.php","path":"/EnterpriseSMSV2/EnterpriseSMSWS.php","href":"http://202.129.232.190:8585/EnterpriseSMSV2/EnterpriseSMSWS.php"},"method":"POST","headers":{"User-Agent":"node-soap/0.8.0","Accept":"text/html,application/xhtml+xml,application/xml,text/xml;q=0.9,*/*;q=0.8","Accept-Encoding":"none","Accept-Charset":"utf-8","Connection":"close","Host":"202.129.232.190:8585","Content-Length":0,"Content-Type":"text/xml; charset=utf-8","SOAPAction":"\"\""}}}

Seems you are requesting REST API.
Response format for SOAP UI is XML. But for REST API is JSON. Then your are getting JSON format response. Thats why you are getting [object object] when you try to print that. So check out how to handle JSON.

Related

how to send a post request to a SOAP API in axios with basic AUTH?

I am sending a post request to a soap endpoint in node.js using AXIOS, but as result, I get this error:
KPS connection is failed! Detailed Exception Message is: com.sun.xml.internal.messaging.saaj.soap.SOAPVersionMismatchException: Unable to create envelope from given source because the namespace was not recognized
What does this error mean? What should I do?
I don't know what I am doing wrong. I never use a SOAP endpoint and I don't know about JAVA.
'<soap:Envelope xmlns:soap="http://wwww.w3.org/2003/05/soap-envelope" xmlns:ns="http://kps.nvi.gov.tr/2021/04/01">
<soap:Body>
<ns:Query>
<ns:List>
<ns:QueryCriteria>
<ns:itemNumber>093323</ns:ItemNumber>
</ns:QueryCriteria>
</ns:List>
</ns:Query>
</soap:Body>
</soap:Envelope>';
const data = await axios
.post(URL, body, {
headers: {
'Content-Type': 'text/xml',
Username: 'username',
Password: 'pasword',
Authorization: 'Basic auth',
},
})
.then(d => console.log('DATA =>', d?.data))
.catch(e => console.log(e.response.data));
so, how should I send the request? Where is wrong?

Node.js Twilio make calls using REST API

I am trying to make call from the Twilio REST API but I am getting an error, looks like I missed something, any help will appreciate:
var options = { method: 'POST',
url: 'https://xxxxxxxxxxxx#api.twilio.com/2010-04-01/Accounts/xxxxxxxxxxx/Calls',
headers:
{
'Cache-Control': 'no-cache',
'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' },
formData:
{ To: '+919200070974',
From: '14245060471',
Url: '<?xml version="1.0" encoding="UTF-8"?>\n<Response>\n <Say voice="woman">This is me....</Say>\n</Response>'} };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
Now I set url parameters but its showing invalid
<?xml version='1.0' encoding='UTF-8'?>
<TwilioResponse>
<RestException>
<Code>21205</Code>
<Message>Url is not a valid url: <?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say voice="woman">This is me....</Say>
</Response></Message>
<MoreInfo>https://www.twilio.com/docs/errors/21205</MoreInfo>
<Status>400</Status>
</RestException>
</TwilioResponse>
I am not getting where I have to set URL parameter, I didn't find in the documentation clearly what I have to set.
Twilio developer evangelist here.
What you need to do in this case, is send to Twilio a URL. When the call connects, Twilio will then make a request to that URL to get the TwiML response.
From the documentation:
When you initiate a call through the REST API, Twilio makes a synchronous HTTP request to the URL found in the value of the 'Url' POST parameter, in order to retrieve TwiML for handling the call. This request is identical to the request Twilio sends when receiving a phone call to one of your Twilio numbers. URLs must contain a valid hostname (underscores are not permitted).
So, your formData here should be:
formData: {
To: '+919200070974',
From: '14245060471',
Url: 'https://example.com/twiml'
}
And the URL at https://example.com/twiml should respond with the TwiML you defined originally.
twilio has an npm library already.
you can follow their Node.js Guide
// Twilio Credentials
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
// require the Twilio module and create a REST client
const client = require('twilio')(accountSid, authToken);
client.messages
.create({
to: '+15558675310',
from: '+15017122661',
body: 'This is the ship that made the Kessel Run in fourteen parsecs?',
})
.then(message => console.log(message.sid));

Error auth using soap-node

I have a problem with soap-node, my header have auth:
XML-service SOAP
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<Autentication xmlns="http://tempuri.org/">
<Pass>string</Pass>
<Us>string</Us>
</Autentication>
</soap:Header>
<soap:Body>
<getdata xmlns="http://tempuri.org/" />
</soap:Body>
</soap:Envelope>
App.js - Node.js
var soap = require('soap');
var url = "http://localhost/abc/example.asmx?WSDL"
var Autentication = {
"Autentication": {
"Pass" : "david",
"Us" : "hackro"
}
}
var args = {}
soap.createClient(url, function(err, client) {
if(err)return console.log(err)
client.addSoapHeader(Autenticacion)
client.ObtieneKey(args, function(err, result,body) {
if(err) return console.log(body)
console.log(result);
console.log(body);
})
})
But my auth fail because return empty
{ data: "" }
I see this answer but it doesn't work.
I solved my problem sending my header in this way
var Autentication ='<Autentication xmlns="http://tempuri.org/">Pass>david</Pass><Us>hackro</Us>/Autentication></soap:Header>'
Add header
client.addSoapHeader(Autentication)
Good Luck

node.js request fails for umts Stick Webserver (huawei)

i´m trying to get websites / xml objects from the huawei umts stick internal web gui.
I´ve written a wrapper in c using libcurl which works fine. Now i want to port this to node using request.
When i call a url with curl from console like this:
curl -G "http://192.168.1.1/api/monitoring/status"
I get normal result:
<?xml version="1.0" encoding="UTF-8"?>
<response>
<ConnectionStatus>901</ConnectionStatus>
<SignalStrength>99</SignalStrength>
<SignalIcon>5</SignalIcon>
<CurrentNetworkType>4</CurrentNetworkType>
<CurrentServiceDomain>3</CurrentServiceDomain>
<RoamingStatus>0</RoamingStatus>
<BatteryStatus></BatteryStatus>
<BatteryLevel></BatteryLevel>
<simlockStatus></simlockStatus>
</response>
When i try to call this site with request:
var request = require("request");
var options = {
url: "http://192.168.1.1/api/monitoring/status"
};
request.get(options, function(error, response, body) {
if(error)
{
console.log(error);
}
console.log("statusCode: " + response.statusCode);
console.log("statusText: " + response.statusText);
console.log(body);
});
I got an 400 Error:
statusCode: 400
statusText: undefined
<HTML><HEAD>
<TITLE>IPWEBS - 400 Bad Request</TITLE>
</HEAD>
<BODY><H2>400 Bad Request</H2>
<P>The request generated an error response.</P>
</BODY>
</HTML>
Any idea on this subject?
It could be that curl is sending a header that the server requires. Try changing your options to:
var options = {
url: "http://192.168.1.1/api/monitoring/status",
headers: {
'User-Agent': 'curl/7.30.0',
'Accept': '*/*'
}
}

Soap from Node.js

How to generate soap request in node.js for the below xml
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cred="http://credential.transport.v1.api.cmpublish.clickability.com" xmlns:tran="http://transport.v1.api.cmpublish.clickability.com">
<soapenv:Header>
<cred:credentials username="" password="" customerID=""/>
</soapenv:Header>
<soapenv:Body>
<tran:getSubscriberByEmail>
<email></email>
<domainID></domainID>
</tran:getSubscriberByEmail>
</soapenv:Body>
</soapenv:Envelope>
If you've got a WSDL to point things at, I've found node-soap to be straight forward.
From their readme:
var soap = require('soap');
var url = 'http://example.com/wsdl?wsdl';
var args = {name: 'value'};
soap.createClient(url, function(err, client) {
client.MyFunction(args, function(err, result) {
console.log(result);
});
});

Resources