Node.js Examples
The following example uses the https library. To install, just type
npm install https
in the directory where you will run node for your file.Listing all Inventory for initial data load
var https = require('https');
var data = {'key': 'NHMJCH5CKPG2D4LA7QFFPMKA', 'includeItemsWithQuantityZero': false};
var options = {
host: 'user.traxia.com',
path: '/app/api/inventory',
port: '443',
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
};
var callback = function(response) {
if (response.statusCode == 200) {
var body = '';
response.on('data', function(d) {
body += d;
});
response.on('end', function() {
var parsed = JSON.parse(body);
//DO SOMETHING WITH YOUR PARSED DATA HERE
});
response.on('error', function(err) {
console.log(err.message);
});
} else {
console.log("HTTP Status: "+response.statusCode);
}
}
var req = https.request(options, callback);
req.on('error', function(error) {
console.log(e.message);
});
req.write(JSON.stringify(data));
req.end();
Listing changes in inventory based on a UNIX-style timestamp (Milliseconds since the Epoch)
var https = require('https');
var modifiedSince = Date.parse("2014-07-28 13:10 GMT");
var data = {'key': 'NHMJCH5CKPG2D4LA7QFFPMKA', 'modifiedSince': modifiedSince, 'includeItemsWithQuantityZero': true, 'includeInactiveItems': true };
var options = {
host: 'user.traxia.com',
path: '/app/api/inventory',
port: '443',
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
};
var callback = function(response) {
if (response.statusCode == 200) {
var body = '';
response.on('data', function(d) {
body += d;
});
response.on('end', function() {
var parsed = JSON.parse(body);
//DO SOMETHING WITH YOUR PARSED DATA HERE
});
response.on('error', function(err) {
console.log(err.message);
});
} else {
console.log("HTTP Status: "+response.statusCode);
}
}
var req = https.request(options, callback);
req.on('error', function(error) {
console.log(e.message);
});
req.write(JSON.stringify(data));
req.end();
Last modified 2yr ago