1. Overview
This tutorial provides technical guidance on extending your application's connection with GHTK delivery system in a simple, high-performance and secure manner.
1.1. Endpoint & Variables
These variables will be used in this API document.
Variables | Description | STAGING | PRODUCTION |
---|---|---|---|
OPEN_API | Open API services | https://services-staging.ghtklab.com | https://services.giaohangtietkiem.vn |
CUSTOMER_WEBSITE | Customer website | https://khachhang-staging.ghtklab.com | https://khachhang.giaohangtietkiem.vn |
Variables | Description |
---|---|
API_TOKEN | This API token key can be found on customer websites. These token could be located at CUSTOMER_WEBSITE /web/thong-tin-shop/tai-khoan |
PARTNER_CODE | Shop code or Private partner code |
MESSAGE | API response message |
ERROR_MESSAGE | Error message for failed request |
LOG_ID | Log ID for tracing |
1.2. Token header
API Token Creation Guide
- Log in to your GHTK account at: https://khachhang.giaohangtietkiem.vn/web.
- Access the API tokens management page: https://khachhang.giaohangtietkiem.vn/web/thong-tin-shop/cau-hinh-api.
- On this page, you can manage the tokens you have created, add new ones, or remove API_TOKEN.
To create a new token, please click the Create Token button in the top right corner of the screen.
Enter information for your API_TOKEN:
-
Token Name: A memorable name for your integration service.
-
Expiration Date: The validity period of the token.
-
Select access permissions for the token (e.g., Create order, Calculate order fees, Get order status, etc.).
Use the API_TOKEN to authenticate requests with the OpenAPI system.
GET /services/authenticated HTTP/1.1
Host: {OPEN_API}
Token: {API_TOKEN}
X-Client-Source: {PARTNER_CODE}
1.3. Request format
GHTK API supports 2 content types: application/x-www-form-urlencoded and application/json.
- API requests need to be in either x-www-form or json.
- Default is application/x-www-form-urlencoded
- Using api /services/authenticated to check the connection to the GHTK system.
application/x-www-form-urlencoded
POST /services/authenticated HTTP/1.1
Host: {OPEN_API}
Token: {API_TOKEN}
X-Client-Source: {PARTNER_CODE}
Content-Type:application/x-www-form-urlencoded
field1=value1&field2=value2
application/json
POST /services/authenticated HTTP/1.1
Token: {API_TOKEN}
X-Client-Source: {PARTNER_CODE}
Content-Type:application/x-www-form-urlencoded
{"field1":value1,"field2":value2}
1.4. Response format
Token verification failed:
HTTP/1.1 403 Forbidden Content-Type:application/json; charset=UTF-8 Content-Length: 0
Token verification succeeded
Content type: JSON
{
"success":true,
"message":"{MESSAGE}",
"log_id":"{LOG_ID}",
"data": ".."
}
Token verification succeeded but error occurred
Content type: JSON
{
"success": false,
"message": "{ERROR_MESSAGE}",
"error_code": "{ERROR_CODE}",
"log_id": "{LOG_ID}"
}