Node.js Examples
The following example uses the https library. To install, just type
1
npm install https
Copied!
in the directory where you will run node for your file.Listing all Inventory for initial data load
1
var https = require('https');
2
var data = {'key': 'NHMJCH5CKPG2D4LA7QFFPMKA', 'includeItemsWithQuantityZero': false};
3
var options = {
4
host: 'user.traxia.com',
5
path: '/app/api/inventory',
6
port: '443',
7
method: 'POST',
8
headers: {
9
'Accept': 'application/json',
10
'Content-Type': 'application/json'
11
}
12
};
13
var callback = function(response) {
14
if (response.statusCode == 200) {
15
var body = '';
16
response.on('data', function(d) {
17
body += d;
18
});
19
20
response.on('end', function() {
21
var parsed = JSON.parse(body);
22
//DO SOMETHING WITH YOUR PARSED DATA HERE
23
});
24
25
response.on('error', function(err) {
26
console.log(err.message);
27
});
28
} else {
29
console.log("HTTP Status: "+response.statusCode);
30
}
31
}
32
var req = https.request(options, callback);
33
req.on('error', function(error) {
34
console.log(e.message);
35
});
36
req.write(JSON.stringify(data));
37
req.end();
Copied!
Listing changes in inventory based on a UNIX-style timestamp (Milliseconds since the Epoch)
1
var https = require('https');
2
var modifiedSince = Date.parse("2014-07-28 13:10 GMT");
3
var data = {'key': 'NHMJCH5CKPG2D4LA7QFFPMKA', 'modifiedSince': modifiedSince, 'includeItemsWithQuantityZero': true, 'includeInactiveItems': true };
4
var options = {
5
host: 'user.traxia.com',
6
path: '/app/api/inventory',
7
port: '443',
8
method: 'POST',
9
headers: {
10
'Accept': 'application/json',
11
'Content-Type': 'application/json'
12
}
13
};
14
var callback = function(response) {
15
if (response.statusCode == 200) {
16
var body = '';
17
response.on('data', function(d) {
18
body += d;
19
});
20
21
response.on('end', function() {
22
var parsed = JSON.parse(body);
23
//DO SOMETHING WITH YOUR PARSED DATA HERE
24
});
25
26
response.on('error', function(err) {
27
console.log(err.message);
28
});
29
} else {
30
console.log("HTTP Status: "+response.statusCode);
31
}
32
}
33
var req = https.request(options, callback);
34
req.on('error', function(error) {
35
console.log(e.message);
36
});
37
req.write(JSON.stringify(data));
38
req.end();
Copied!
Last modified 1mo ago
Copy link