I\'m trying to make a HTTP POST request to the google QPX Express API [1] using nodejs and request [2].
My code l
you can pass the json object as the body(third argument) of the fetch request.
You don't want multipart, but a "plain" POST request (with Content-Type: application/json
) instead. Here is all you need:
var request = require('request');
var requestData = {
request: {
slice: [
{
origin: "ZRH",
destination: "DUS",
date: "2014-12-02"
}
],
passengers: {
adultCount: 1,
infantInLapCount: 0,
infantInSeatCount: 0,
childCount: 0,
seniorCount: 0
},
solutions: 2,
refundable: false
}
};
request('https://www.googleapis.com/qpxExpress/v1/trips/search?key=myApiKey',
{ json: true, body: requestData },
function(err, res, body) {
// `body` is a js object if request was successful
});
I worked on this for too long. The answer that helped me was at: send Content-Type: application/json post with node.js
Which uses the following format:
request({
url: url,
method: "POST",
headers: {
"content-type": "application/json",
},
json: requestData
// body: JSON.stringify(requestData)
}, function (error, resp, body) { ...