Skip to content

An unofficial Node SDK for Thailand Post that consumes the official API

License

Notifications You must be signed in to change notification settings

itsKaynine/thailand-post

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

An unofficial Node SDK for Thailand Post that consumes the official API

Resources

License

Stars

Watchers

Forks

Packages

No packages published