15. Đăng đơn
Create Order
The order registration API is similar to the regular account order registration API, but in the request, you need to include the B2C account token information in the header X-Refer-Token.For example, the shop HappyShop sells products on the e-commerce platform SmileB2C.
HappyShop has the token APITokenSample-ca441e70288cB0515F310742.
SmileB2C has the token B2CToken-hlsheiwquhrksadlfkjahsdfjaaljh.
In the order registration request for the HappyShop account sent from the SmileB2C server, you need to set an additional header X-Refer-Token with the value being the token of the SmileB2C account
- HTTP
- CURL
- PHP
POST /services/shipment/order HTTP/1.1
Token: APITokenSample-ca441e70288cB0515F310742
X-Refer-Token: B2CToken-hlsheiwquhrksadlfkjahsdfjaaljh
Content-Type: application/json
{
"products": [{
"name": "bút",
"weight": 0.1
}, {
"name": "tẩy",
"weight": 0.2
}],
"order": {
"id": "123123a",
"pick_name": "HCM-nội thành",
"pick_address": "590 CMT8 P.11",
"pick_province": "TP. Hồ Chí Minh",
"pick_district": "Quận 3",
"pick_tel": "0911222333",
"tel": "0911222333",
"name": "GHTK - HCM - Noi Thanh",
"address": "123 nguyễn chí thanh",
"province": "TP. Hồ Chí Minh",
"district": "Quận 1",
"is_freeship": "1",
"pick_date": "2016-09-30",
"pick_money": 47000,
"note": "Khối lượng tính cước tối đa: 1.00 kg",
"value": 3000000
"tags": [1,7]
}
}
curl -X POST -H "Token: APITokenSample-ca441e70288cB0515F310742X" \
-H "X-Refer-Token: B2CToken-hlsheiwquhrksadlfkjahsdfjaaljh" \
-H "Content-Type: application/json" \
-d '{"products":[{"name":"bút","weight":0.1},{"name":"tẩy","weight":0.2}],"order":{"id":"123123a","pick_name":"HCM-nội thành","pick_address":"590 CMT8 P.11","pick_province":"TP. Hồ Chí Minh","pick_district":"Quận 3","pick_tel":"0911222333","tel":"0911222333","name":"GHTK - HCM - Noi Thanh","address":"123 nguyễn chí thanh","province":"TP. Hồ Chí Minh","district":"Quận 1","is_freeship":"1","pick_date":"2016-09-30","pick_money":47000,"note":"Khối lượng tính cước tối đa: 1.00 kg","value":3000000}}' "https://services.giaohangtietkiem.vn/services/shipment/order"
$order ='{
"products": [{
"name": "bút",
"weight": 0.1
}, {
"name": "tẩy",
"weight": 0.2
}],
"order": {
"id": "123123a",
"pick_name": "HCM-nội thành",
"pick_address": "590 CMT8 P.11",
"pick_province": "TP. Hồ Chí Minh",
"pick_district": "Quận 3",
"pick_tel": "0911222333",
"tel": "0911222333",
"name": "GHTK - HCM - Noi Thanh",
"address": "123 nguyễn chí thanh",
"province": "TP. Hồ Chí Minh",
"district": "Quận 1",
"is_freeship": "1",
"pick_date": "2016-09-30",
"pick_money": 47000,
"note": "Khối lượng tính cước tối đa: 1.00 kg",
"value": 3000000
}
}';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://services.giaohangtietkiem.vn/services/shipment/order",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $order,
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"Token: APITokenSample-ca441e70288cB0515F310742",
"X-Refer-Token: B2CToken-hlsheiwquhrksadlfkjahsdfjaaljh",
"Content-Length: " . strlen($order),
),
));
$response = curl_exec($curl);
curl_close($curl);
echo 'Response: ' . $response;
?>