TNH API (1.0.0)

Download OpenAPI specification:Download

Introduction

TNH API Document for shop

  • Welcome to the TNH API! You can use our API to access TNH API endpoints, which can get information on various trackings, businesses and payments in our database.

  • We have language bindings in HTTP and you can view code examples in the dark area to the right.

As you scroll, you'll see code examples for working with the API in different programming languages in the dark area to the right (or as part of the content on mobile). You can switch the language used with the tabs at the top right (or from the nav menu at the top left on mobile).

The portal provides documentation for the following APIs and services:

  • Package API. Create delivery orders, generate waybills, and cancel orders.
  • Location API. Get location informations.

All TNH APIs are RESTful APIs.

Base URL by environment

Production base URL

  • URL: https://gateway.tnhlog.vn

Staging base URL

  • URL: https://stg-apigw.tnhlog.vn

Rate limiting

In order to provide a high-quality of service for all customers, our API is rate limited. If the rate limit is exceeded, the API responds with an HTTP 400 API rate limit exceeded status code, and you get temporarily blocked from accessing the API. In this case, retry your request after a few hours.

Authentication

Returns a new Bearer access token.

Prerequisites

To make requests to this endpoint, you need to have the Email and Password. You can obtain by registration new account here:

  1. Production: khachhang.tnhlog.vn
  2. Staging: stg-khachhang.tnhlog.vn

Implementation flow

Your implementation must adhere to this flow:

  1. Login and get the access_token.
  2. Store the token, along with the expiration timestamp, in a persistent storage.
  3. Attach the token as a Bearer token with every API request to a TNH API. This means that for the Authorization HTTP header, the value must be Bearer <INSERT ACCESS TOKEN>.
  4. This token is live forever

Login

Request Body schema: application/json
email
required
string (Email)
password
required
string (Password)

Responses

Request samples

Content type
application/json
{
  • "email": "string",
  • "password": "string"
}

Response samples

Content type
application/json
{
  • "success": true,
  • "access_token": "37|fzN5sMtrRKmy4VSXK1jwJqbnkttCsJ3aJFwfA8mp"
}

Get Profile

Authorizations:
APIKeyHeader

Responses

Response samples

Content type
application/json
{
  • "id": "SEL00004793",
  • "name": "Nguyen van A",
  • "phone": "090000000",
}

Logout

Authorizations:
APIKeyHeader
Request Body schema: application/json
Authorization
required
string (bearer)

Responses

Request samples

Content type
application/json
{
  • "Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9"
}

Response samples

Content type
application/json
{
  • "success": true
}

Package

The purpose of the Package API is to create delivery orders, generate awb, and cancel orders...

Get All Packages

Authorizations:
APIKeyHeader
header Parameters
Authorization
required
any

Your Bearer token.

Responses

Response samples

Content type
application/json
[
  • {
    },
  • {
    }
]

Show Package

Authorizations:
APIKeyHeader
path Parameters
package-code
required
string (Package code)
Example: BAM291120019982

Responses

Response samples

Content type
application/json
{
  • "code": "PKG2210897312",
  • "package_code": "PKG10897312",
  • "tracking_number": "LMP0170517004VNA",
  • "port_code": "HT-TRG-I",
  • "cod": 7000000,
  • "weight": 10,
  • "size_l": 20,
  • "size_h": 30,
  • "size_w": 30,
  • "product": "Iphone 14 Promax",
  • "product_value": 40000000,
  • "shipping_fee": 18000,
  • "insurance_fee": 20000,
  • "is_insurance_fee": true,
  • "receiver_name": "Tran Van A",
  • "receiver_phone": "090 9332 982",
  • "receiver_address": "81 Hoàng Minh Giám",
  • "receiver_port_code": "R2587289",
  • "receiver_address_level_1": "Phường 4",
  • "receiver_address_level_2": "Quận Phú Nhuận",
  • "receiver_address_level_3": "Thành Phố Hồ Chí Minh",
  • "sender_phone": "0922736283",
  • "sender_name": "Test TRG",
  • "sender_address": "5/34 Thủ Khoa Huân",
  • "sender_port_code": "R2587289",
  • "sender_address_level_1": "Phường Long Bình",
  • "sender_address_level_2": "Quận 9",
  • "sender_address_level_3": "Thành Phố Hồ Chí Minh",
  • "status": "Waiting_for_pickup",
  • "notes": "Hàng dễ vỡ, xin nhẹ tay",
}

Create Package

Authorizations:
APIKeyHeader
Request Body schema: application/json
code
required
string (Code)
cod
required
integer (Cash on Devliery - COD)
weight
required
integer (Weight)
size_l
required
integer (Length)
size_h
required
integer (Height)
size_w
required
integer (Width)
product
string (Product)
Array of objects (Product)
product_value
required
integer (Product value)
is_insurance_fee
required
boolean (Is Insurance Fee (product value > 3000000, insurance = productValue*0.005))
receiver_name
required
string (Receiver's name)
receiver_phone
required
string (Receiver's phone)
receiver_address
required
string (Receiver's address)
receiver_port_code
required
string (Receiever's port code)
sender_address
required
string (Sender's address)
sender_port_code
required
string (Sender's port code)
notes
required
string (Note)
quantity
required
integer (quantity)
address_type
string (address_type)
Default: "work"

value "home" or "work"

sender_payment
boolean (sender_payment)
Default: true

true: Sender pay fee; false: Receiver pay fee

delivery_options
integer (delivery_options)
Default: 1

1: can open, try product is not allowed or 2: Not co-checked

Responses

Request samples

Content type
application/json
{
  • "code": "PKG2210897312",
  • "cod": 7000000,
  • "weight": 10,
  • "size_l": 20,
  • "size_h": 30,
  • "size_w": 30,
  • "product": "Iphone 14 Promax",
  • "package_products": [
    ],
  • "product_value": 40000000,
  • "insurance_fee": 20000,
  • "is_insurance_fee": true,
  • "receiver_name": "Tran Van A",
  • "receiver_phone": "090 9332 982",
  • "receiver_address": "81 Hoàng Minh Giám",
  • "receiver_port_code": "R2587289",
  • "sender_address": "5/34 Thủ Khoa Huân",
  • "sender_port_code": "R2587289",
  • "notes": "Hàng dễ vỡ, xin nhẹ tay",
  • "quantity": 1
}

Response samples

Content type
application/json
{
  • "code": "PKG2210897312",
  • "package_code": "PKG10897312",
  • "tracking_number": "LMP0170517004VNA",
  • "port_code": "HT-TRG-I",
  • "cod": 7000000,
  • "weight": 10,
  • "size_l": 20,
  • "size_h": 30,
  • "size_w": 30,
  • "product": "Iphone 14 Promax",
  • "product_value": 40000000,
  • "shipping_fee": 18000,
  • "insurance_fee": 20000,
  • "is_insurance_fee": true,
  • "receiver_name": "Tran Van A",
  • "receiver_phone": "090 9332 982",
  • "receiver_address": "81 Hoàng Minh Giám",
  • "receiver_port_code": "R2587289",
  • "receiver_address_level_1": "Phường 4",
  • "receiver_address_level_2": "Quận Phú Nhuận",
  • "receiver_address_level_3": "Thành Phố Hồ Chí Minh",
  • "sender_phone": "0922736283",
  • "sender_name": "Test TRG",
  • "sender_address": "5/34 Thủ Khoa Huân",
  • "sender_port_code": "R2587289",
  • "sender_address_level_1": "Phường Long Bình",
  • "sender_address_level_2": "Quận 9",
  • "sender_address_level_3": "Thành Phố Hồ Chí Minh",
  • "status": "Waiting_for_pickup",
  • "notes": "Hàng dễ vỡ, xin nhẹ tay",
}

Get Shipping Fees

Authorizations:
APIKeyHeader
Request Body schema: application/json
seller_code
string (Seller code)

Use seller code when not authentication

sender_port_code
required
string (Sender's port code)
Default: "R0001"
receiver_port_code
required
string (Receiver's port code)
Default: "R0042"
weight
required
integer (Weight - gram)
Default: 200

Responses

Request samples

Content type
application/json
[
  • {
    }
]

Response samples

Content type
application/json
{
  • "shipping_fee": 27000,
  • "min_est_leadtime": 1,
  • "max_est_leadtime": 2,
  • "max_est_return_leadtime": 8
}

Get Insurance Fees

Authorizations:
APIKeyHeader
Request Body schema: application/json
product_value
required
integer (product value > 30000000)

Responses

Request samples

Content type
application/json
{
  • "product_value": 4000000
}

Response samples

Content type
application/json
{
  • "insurance_fee": 20000
}

Package Tracking History

Authorizations:
APIKeyHeader
query Parameters
code
required
string (Package code)
Example: code=BAM291120019982

Responses

Response samples

Content type
application/json
{
  • "receiver_name": "Nguyễn Văn A",
  • "receiver_phone": "0972312231",
  • "receiver_address": "132A Nguyễn Trọng Tuyển",
  • "receiver_address_level_1": "Phường 8",
  • "receiver_address_level_2": "Quận Phú Nhuận",
  • "receiver_address_level_3": "Thành Phố Hồ Chí Minh",
  • "sender_name": "Nguyễn Văn A",
  • "sender_phone": "0972312231",
  • "sender_address": "132A Nguyễn Trọng Tuyển",
  • "sender_address1_level_1": "Phường 8",
  • "sender_address_level_2": "Quận Phú Nhuận",
  • "sender_address_level_3": "Thành Phố Hồ Chí Minh",
  • "status": "Delivered",
  • "cod": 100000,
  • "audits": [
    ]
}

Get All Package Statuses

Authorizations:
APIKeyHeader

Responses

Response samples

Content type
application/json
[
  • {
    },
  • {
    },
  • {
    },
  • {
    },
  • {
    },
  • {
    },
  • {
    },
  • {
    },
  • {
    },
  • {
    },
  • {
    },
  • {
    },
  • {
    },
  • {
    },
  • {
    },
  • {
    },
  • {
    },
  • {
    },
  • {
    },
  • {
    },
  • {
    },
  • {
    },
  • {
    }
]

Cancel Package

Authorizations:
APIKeyHeader
path Parameters
code
required
string (Package code)
Example: BAM291120019982

Responses

Response samples

Content type
application/json
{
  • "success": true
}

Get Package Awb

Authorizations:
APIKeyHeader
Request Body schema: application/json
codes
required
Array of arrays (codes)

The codes can be used as code or package_code

type
string (type)

There are two types:

  • pdf: Return PDF file
  • link: Return link AWB
Type "pdf" will be the default option if "type" not provided

Responses

Request samples

Content type
application/json
{
  • "codes": [
    ],
  • "type": "link"
}

Response samples

Content type
application/json
{
  • "link": "link-to-file-awb"
}

Location

Show address with port codes.

Get ThreePL address

Authorizations:
APIKeyHeader
path Parameters
limit
required
integer (limit)
Example: 10

Responses

Response samples

Content type
application/json
[
  • {
    },
  • {
    }
]

WareHouse

Create/Update warehouse

Create WareHouse

Authorizations:
APIKeyHeader
Request Body schema: application/json
name
string (name) >= 3 characters

This field is optional, if not provided, seller's name will be used

phone
number (phone) [ 10 .. 11 ] characters

This field is optional, if not provided, seller's phone will be used

address
required
string (address)
address_port_code
required
string (address_port_code)

Responses

Request samples

Content type
application/json
{
  • "name": "Shop em bé",
  • "phone": "0987234211",
  • "address": "132A Nguyễn Trọng Tuyển",
  • "address_port_code": "R000911"
}

Response samples

Content type
application/json
{
  • "warehouse_code": "WH000001",
  • "phone": "0987234211",
  • "address": "132A Nguyễn Trọng Tuyển",
  • "ward": "Phường 8",
  • "district": "Quận Phú Nhuận",
  • "province": "Thành Phố Hồ Chí Minh"
}

Get WareHouse By Code

Authorizations:
APIKeyHeader
path Parameters
code
required
string (code)
Example: WH000001

Responses

Response samples

Content type
application/json
{
  • "warehouse_code": "WH000001",
  • "phone": "0987234211",
  • "address": "132A Nguyễn Trọng Tuyển",
  • "ward": "Phường 8",
  • "district": "Quận Phú Nhuận",
  • "province": "Thành Phố Hồ Chí Minh"
}

Update WareHouse By Code

Authorizations:
APIKeyHeader
Request Body schema: application/json
name
string (name) >= 3 characters
phone
number (phone) [ 10 .. 11 ] characters
address_port_code
string (address_port_code)
address
string (address)

Responses

Request samples

Content type
application/json
{
  • "name": "Shop em bé",
  • "phone": "0987234211",
  • "address_port_code": "R000911",
  • "address": "132A Nguyễn Trọng Tuyển"
}

Response samples

Content type
application/json
{
  • "warehouse_code": "WH000001",
  • "phone": "0987234211",
  • "address": "132A Nguyễn Trọng Tuyển",
  • "ward": "Phường 8",
  • "district": "Quận Phú Nhuận",
  • "province": "Thành Phố Hồ Chí Minh"
}

Webhooks

Webhooks help you register to listen to events arising from Quick.vn's system, for example:

  • Receive package status change
  • Package has dim weight changed

Webhook events

Event Webhook is triggered when...
Package status Update status package
Package re-weight Update package dim weight

Receive a Webhook

Sample webhook payloads

package status

Fields Type Notes
type String required
code String required
status String required
epod String
reason String
trace_id String
{
    "type": "package-update-status",
    "code": "PKG2210897312",
    "reason": "recipient reschedule",
    "epod": "https://domain.com/url-to-epod-image-here",
    "status": "Delivery_failed_attempt"
}

package re-weight

Fields Type Notes
type String required
code String required
length float required
width float required
height float required
weight float required
trace_id String required
{
    "type": "package-re-weight",
    "code": "PKG2210897312",
    "length": 10.02,
    "width": 12.01,
    "height": 8.2,
    "weight": 2.5
}