4. Calculate Shipping Fee API
This API provides the shipping fee based on given pickup & delivery address and the package weight.
Request
Endpoint
GET /services/shipment/fee
Headers
Token: {API_TOKEN}
X-Client-Source: {PARTNER_CODE}
Input parameters:
Parameter | Datatype | Mandatory (Y)/(N) | Description |
---|---|---|---|
pick_address_id | String | N | Address ID to pick up the order. This input takes precedence in identifying the pick up address if not null/empty. These ID can be found in tab "Edit shop information". If pick_address_id is valid, province name, district name,… of pick up address will be following this ID. |
pick_address | String | N | Address string to pick up the order |
pick_province | String | Y | Province to pick up the order |
pick_district | String | Y | District to pick up the order |
pick_ward | String | N | Ward to pick up the order |
pick_street | String | N | Street to pick up the order |
address | String | N | Detailed address to deliver the order |
province | String | Y | Province to deliver the order |
district | String | Y | District to deliver the order |
ward | String | N | Ward to deliver the order |
street | String | N | Street to deliver the order |
weight | Integer | Y | Declared weight of the product (gram) |
value | Integer | N | Declared monetary value of the order package. The insurance fee is calculated based on this value. (in VND) |
transport | String | N | This is the transportation method to deliver the parcel. Possible value is "fly" or "road". If the transportation method is invalid, GHTK will switch automatically to default transportation method |
deliver_option | String | Y | Possible value is "xteam" or "none". Using "xteam" when the delivery method is Xfast. |
tags | Array | N | Possible value is [1] if the order has fragile product or [7] if the order has farm product, dry food. |
Code
- HTTP
- CURL
- PHP
GET /services/shipment/fee?address=P.503%20t%C3%B2a%20nh%C3%A0%20Auu%20Vi%E1%BB%87t,%20s%E1%BB%91%201%20L%C3%AA%20%C4%90%E1%BB%A9c%20Th%E1%BB%8D&province=H%C3%A0%20n%E1%BB%99i&district=Qu%E1%BA%ADn%20C%E1%BA%A7u%20Gi%E1%BA%A5y&pick_province=H%C3%A0%20N%E1%BB%99i&pick_district=Qu%E1%BA%ADn%20Hai%20B%C3%A0%20Tr%C6%B0ng&weight=1000&value=3000000&deliver_option=xteam HTTP/1.1
Token: {API_TOKEN}
X-Client-Source: {PARTNER_CODE}
curl -X GET -H "Token: APITokenSample-ca441e70288cB0515F310742" \
"https://services.giaohangtietkiem.vn/services/shipment/fee?address=P.503%20t%C3%B2a%20nh%C3%A0%20Auu%20Vi%E1%BB%87t,%20s%E1%BB%91%201%20L%C3%AA%20%C4%90%E1%BB%A9c%20Th%E1%BB%8D&province=H%C3%A0%20n%E1%BB%99i&district=Qu%E1%BA%ADn%20C%E1%BA%A7u%20Gi%E1%BA%A5y&pick_province=H%C3%A0%20N%E1%BB%99i&pick_district=Qu%E1%BA%ADn%20Hai%20B%C3%A0%20Tr%C6%B0ng&weight=1000&value=3000000&deliver_option=xteam&tags%5B%5D=1"
<?php
$data = array(
"pick_province" => "Hà Nội",
"pick_district" => "Quận Hai Bà Trưng",
"province" => "Hà nội",
"district" => "Quận Cầu Giấy",
"address" => "P.503 tòa nhà Auu Việt, số 1 Lê Đức Thọ",
"weight" => 1000,
"value" => 3000000,
"transport" => "fly",
"deliver_option" => "xteam",
"tags" => [1,7]
);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://services.giaohangtietkiem.vn/services/shipment/fee?" . http_build_query($data),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_HTTPHEADER => array(
"Token: APITokenSample-ca441e70288cB0515F310742",
),
));
$response = curl_exec($curl);
curl_close($curl);
echo 'Response: ' . $response;
?>
Response
Response description
Field | Datatype | Description |
---|---|---|
fee.name | String | Name of applied shipping rate Possible values: area1, area2, area3 |
fee.fee | Integer | Shipping fee amount (in VND) |
fee.insurance_fee | Integer | Insurance fee amount (in VND) |
fee.delivery | Boolean | If the delivery address is supported by GHTK, respone is "true". If it is not supported, the respone is "false". |
Successful request
{
"success": true,
"message": "",
"fee": {
"name": "area1",
"fee": 30400,
"insurance_fee": 15000,
"delivery_type": "only_hanoi",
"a": 3,
"dt": "local",
"extFees": [
{
"display": "(+ 7,400 đ)",
"title": "Phụ phí hàng dễ vỡ",
"amount": 7400,
"type": "fragile"
},
{
"display": "(+ 13,400 đ)",
"title": "Phụ phí hàng nông sản/thực phẩm khô",
"amount": 13400,
"type": "food"
}
],
"delivery": true
}
}
Note:
info
In cases where pick_address_id
has a valid value, the province, district, etc., information of the pickup point will be retrieved based on this address code. The fields pick_province
and pick_district
are not required.
Introduce the variable deliver_option
= xteam
to calculate shipping fees for XFast (an express delivery service).