thailand-post

2.1.0 • Public • Published

Thailand Post SDK

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.

Installation

$ [sudo] npm install thailand-post

Usage

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(...)
});

Track an Item

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);
});

Get shipping rates

var country = "TH"; // Thailand
var weight = 30; // 30g
 
serv.getRates(country, weight, function(err, result) {
    if (err) {
        return console.log(err);
    }
 
    console.log(result);
});

Get all branches

serv.getAllLocations(function(err, result) {
    if (err) {
        return console.log(err);
    }
 
    console.log(result);
});

Search for a branch

var keyword = "คลอง";
 
serv.searchLocation(keyword, function(err, result) {
    if (err) {
        return console.log(err);
    }
 
    console.log(result);
});

Get nearby locations

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);
});

Get countries

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);
});

Advanced Usage

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.

Track items

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);
});

Package Sidebar

Install

npm i thailand-post

Weekly Downloads

0

Version

2.1.0

License

MIT

Last publish

Collaborators

  • itskaynine