An unofficial Node SDK for Thailand Post that consumes the official API.
WARNING
This project contains information that was obtained from reverse-engineering.
In order to legally use the official API, you must send a request to Thailand Post.
$ [sudo] npm install thailand-post
First, you need to import the module and create an instance of the service.
var TrackService = require('thailand-post').TrackService;
var trackService = new TrackService({
lang: "EN" // either EN or TH
});
trackService.init(function(err, serv) {
// ... your code here
// serv.getItem(...)
});
Single item
var barcode = "EN331755897TH";
serv.getItem(barcode, function(err, result) {
if (err) {
return console.log(err);
}
console.log(result);
});
Multiple items
var barcodes = ["EN331755897TH", "RI598984676CN"];
serv.getItems(barcodes, function(err, result) {
if (err) {
return console.log(err);
}
console.log(result);
});
var country = "TH"; // Thailand
var weight = 30; // 30g
serv.getRates(country, weight, function(err, result) {
if (err) {
return console.log(err);
}
console.log(result);
});
serv.getAllLocations(function(err, result) {
if (err) {
return console.log(err);
}
console.log(result);
});
var keyword = "คลอง";
serv.searchLocation(keyword, function(err, result) {
if (err) {
return console.log(err);
}
console.log(result);
});
var latitude = 13.11143;
var longitude = 101.154250;
var numOfResults = 10;
serv.getNearbyLocations(latitude, longitude, numOfResults, function(err, result) {
if (err) {
return console.log(err);
}
console.log(result);
});
You can then use the country code to find shipping rates.
serv.getCountries(function(err, result) {
if (err) {
return console.log(err);
}
console.log(result);
});
This is for anyone who would like to access the SOAP API directly.
Visit the official Thailand Post SOAP API documentation for more information on each operation.
var args = {
user: serv.defaultArgs.user,
password: serv.defaultArgs.password,
lang: serv.defaultArgs.lang,
Barcodes: "EN331755897TH,RI598984676CN"
};
serv.client.GetItems(args, function(err, result) {
if (err) {
return console.log(err);
}
console.log(result);
});