Git Product home page Git Product logo

thailand-post's Introduction

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

thailand-post's People

Contributors

itskaynine avatar

Watchers

Theeraphon Samathi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.