I've been trying to use node-soap library for nodejs to consume a soap service but when i send my request the response from the service is that flightNumber in my request is null.
I Also tried sending the same request that works for me in soap UI in xml format and i got the same error message.
This is my request:
var request = {
"body" : {
"DisplayFlightLegsRQ": {
"flightNumber": "222",
"airlineCode": "BB",
"departureIATACode": "MIA"
"flightDate": {
"departureDateCondition": "SCHEDULE",
"requestTimeStandard": "UTC",
"departureDate": "10-10-2015"
}
}
},
"headers": {"Content-Type": "text/xml;charset=UTF-8"}
}
Call to the soap service:
soap.createClient(url,function(err, client){
client.addHttpHeader('App-name', 'fs');
client.setSecurity(new soap.BasicAuthSecurity('***', '***'));
client.displayFls(request, function(err, result, body) {
console.log(result.body);
parseString(body, function(err, result){
var requestResult = result['SOAP-ENV:Envelope']['SOAP-ENV:Body'][0].DisplayFlightLegsRS[0].return[0];
console.log(requestResult);
})
});
});
is it possible that there is an issue in this soap-node library causing my request to send null parameters? I debugged the request just before being sent and the object is well formatted and it has all the values. Maybe this library is doing an inside transformation from the json request to xml and in that process is erasing the values? or maybe my request is missing something.
I appreciate any help.
Thanks :)
Related
I'm using sendgrid (javascript) to add a new contact to my list.
Within marketing.
var request = require("request");
var options = { method: 'PUT',
url: 'https://api.sendgrid.com/v3/contactdb/lists/193029b7-0b8b-4c0c-948d-47d09a157542/recipients',
headers: { authorization: 'Bearer myapi' },
body: '{"contacts":[{"email": "myemail#gmail.com","unique_name":"hello"}]}' };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
But then I get the message 'acces forbidden'.
Am I using the wrong url?
(The API token is set to administrator all access.)
Thanks!
It looks like there's a few things going on here.
According to the docs, there are not endpoints in the Contact API that accept the method PUT.
After checking our own implementation, it also looks like there's an issue with what you're intending to do.
See the docs for adding multiple recipients to a list:
POST https://api.sendgrid.com/v3/contactdb/lists/{list_id}/recipients HTTP/1.1
Request body:
[
"recipient_id1",
"recipient_id2"
]
In order to use that method, you need to first create the users and retrieve their recipient ID's.
POST https://api.sendgrid.com/v3/contactdb/recipients HTTP/1.1
[
{
"email": "myemail#gmail.com",
"unique_name":"hello"
}
]
Check out the links posted for more information on their usage and response.
I am trying to do a post request with json in a format where I use the option={method, uri, ...} instead of request.get(... because I want to convert this into a function where method, uri, body are the parameters
Im calling this request in node.js to a foreign service. Simple GET requests to that foreign service worked fine. (By the way I did test if it works via postman)
below is the code where i do the request. I have tried without json:true and instead of body, I tried json:{"prod...
request({
headers: {
"Content-type":"application/json;charset=UTF-8",
"Authorization":signature
},
method:'POST',
uri: PATH+`openapi/apis/api/v1/categorization/predict`,
json:true,
body:{"productName": "readymix"}
}, (err, res, body) => {
if(err) console.log(err);
else console.log(body);
})
I keep getting the following error: Unexpected token o in JSON at position 1 The format looks all correct, I dont know why its not working
=====Problem solved=====
removing json:true and fixing body:{"productName": "readymix"} to body:JSON.stringify({"productName": "readymix"}) fixed the problem!
My client posted data from one website to my website using npm request module.
ie as follows.
testservice : function(req , res){
var data = { title : 'my title' , content : 'my content'};
request.post('https://dev.example.com/test' , data , function(err , response ,body){
if (err) console.log(err);
if(response) console.log('statuscode='+response.statuscode);
});
};
I tried to get the JSON data posted to my site from my client's site using request get method , but i didnt get json data output.
Please help me out to get JSON data which is posted using request post method. Thanks.
Try this:
testservice: function(req, res) {
var data = { title: 'my title', content: 'my content' },
options = {
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
};
request.post('https://dev.example.com/test', options, function(err, response, body) {
if (err) console.log(err);
if (response) console.log('statuscode=' + response.statuscode);
});
};
I tried to get the JSON data posted to my site from my client's site using request get method, but i didnt get json data output.
I believe you may be misunderstanding the request.get function. It doesn't "get" the data that was posted to your site, it in fact fires a "get" request off to a particular URL.
If you want to receive data on your site that was POST'ed, then you need to configure your server to listen for POST requests from your friends site and then parse out the posted data from the body of that request.
i.e. in your server code if you're using raw node.js
http.createServer(function(req,res){
if(req.method.toUpperCase() === "POST"){
//code to parse out the data from the post request
}
}).listen(8080)
For more detailed info on parsing out the POST'ed data, see How do you extract POST data in Node.js?
Let me know if this helps, please clarify your question if not.
I am using html on client side and my server side code is on node.js. I have some url's defined in to the nodejs application and I am calling them from my client html file. From node I am calling my REST application which is at another server. This rest application is written in Jersey java web services. I am able to call node.js from my html and from node code I am getting response from Jersey web service module. After receiving this response I am setting it to response object of node.js but this response is not available on html jquery ajax call.
$.ajax({
type :"POST",
dataType: 'json',
data: jsontest,
url: 'http://<code>localhost</code>:9999/hello',
success: function(data) {
console.log('success');
console.log(data);
console.log(data.id);
}, error : function(response) {
console.log(JSON.stringify(response));
}
});
Server side code:
var tmp = req;
var authentication = JSON.stringify(tmp.body.authenticationKey);
console.log("authentication :- "+authentication);
requestObj({
url : "http://<code>restserver</code>:port/restmodule/controller/hello",
method : "POST",
headers : { "Content-Type" : "application/json","pubKey":authentication},
body : JSON.stringify(tmp.body)
},
function (error, res, body) {
indexresponseBody = JSON.stringify(JSON.parse(body).message);
}
);
res.writeHead(200, {'content-type':'text/html'});
console.log("JSON returned from REST "+indexresponseBody);
res.write(indexresponseBody);
res.end();
I am able to get the json and this is printed on node server console. But when I am writing this json to the response(res) object on firebug console I am not able to see this json. Can anybody tell me how can I get this response.
Could be because of async nature of callback, try this -
function (error, resp, body) {
indexresponseBody = JSON.stringify(JSON.parse(body).message);
res.writeHead(200, {'content-type':'text/html'});
console.log("JSON returned from REST "+indexresponseBody);
res.write(indexresponseBody);
res.end();
}
I'm writing a some node code, which to simulate a ASP.NET ajax client call. It is made as a http post request to the server, and I've managed to setup the request headers and body perfectly with the OS X tool CocoaRestClient. With this tool the server responds perfectly as expected.
When I try to do the same thing with Node.js, with the 'request' module, it fails:
My script:
var request = require('request');
request.post({
'uri': 'http://[The Url]/[The Service].asmx/[The Operation]',
'json': '{"callbackcontextkey":"[the context key]",[The set of json formatted key/value pairs] }',
'headers': { }
}, function(e, r, body) {
console.log("Response error: %j", e);
console.log("Response r: %j", r);
console.log("Response body: %j", body);
});
When I'm using the CocoaRestClient tool, all I specify is the Content-Type (application/json) parameter, and then just the request body as specified in the code (the 'json' attribute value).
My code makes the server side return this:
"There was an error processing the request."
And I can also see this in the response:
"jsonerror":"true"
What am I doing wrong? I consider using a network sniffing tool to see the differences...
The json param expects a JavaScript object and request turns it into a JSON string for you.
Try removing the quotes from around it like so:
var request = require('request');
request.post({
'uri': 'http://[The Url]/[The Service].asmx/[The Operation]',
'json': {"callbackcontextkey":"[the context key]",[The set of json formatted key/value pairs] },
'headers': { }
}, function(e, r, body) {
console.log("Response error: %j", e);
console.log("Response r: %j", r);
console.log("Response body: %j", body);
});
Alternatively, you could keep it as a string and set the body param instead of json and it would probably work that way too. More details here: https://npmjs.org/package/request