Tài liệu cho nhà phát triểnBắt đầu
Bắt đầu nhanh
Tạo khóa, gửi một yêu cầu, đọc sơ đồ.
Tạo khóa API
Trong console dành cho nhà phát triển, mở Khóa API và tạo một khóa. Khóa bí mật chỉ hiển thị một lần.
export CARGODUO_API_KEY="cd_live_..."Tạo tác vụ
Với ?wait=60, phản hồi trả về tác vụ đã hoàn tất nếu tác vụ kết thúc trong vòng 60 giây.
curl -X POST "https://runner.cargoduo.com/v1/pack?wait=60" \
-H "Authorization: Bearer $CARGODUO_API_KEY" \
-H "Idempotency-Key: order-1042-v1" \
-H "Content-Type: application/json" \
-d '{
"reference": "order-1042",
"vehicles": [
{
"id": "trailer",
"type": "trailer",
"name": "13.6 m trailer",
"length": 1360,
"width": 245,
"height": 270,
"max_weight": 24000
}
],
"items": [
{
"id": "pallet-eu",
"label": "Euro pallet",
"length": 120,
"width": 80,
"height": 140,
"weight": 450,
"quantity": 18,
"stackable": false
},
{
"id": "carton-a",
"label": "Carton A",
"length": 60,
"width": 40,
"height": 40,
"weight": 12,
"quantity": 40,
"rotation": "upright"
}
],
"options": {
"packing_mode": "auto"
}
}'const res = await fetch("https://runner.cargoduo.com/v1/pack?wait=60", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.CARGODUO_API_KEY}`,
"Idempotency-Key": "order-1042-v1",
"Content-Type": "application/json",
},
body: JSON.stringify({
"reference": "order-1042",
"vehicles": [
{
"id": "trailer",
"type": "trailer",
"name": "13.6 m trailer",
"length": 1360,
"width": 245,
"height": 270,
"max_weight": 24000
}
],
"items": [
{
"id": "pallet-eu",
"label": "Euro pallet",
"length": 120,
"width": 80,
"height": 140,
"weight": 450,
"quantity": 18,
"stackable": false
},
{
"id": "carton-a",
"label": "Carton A",
"length": 60,
"width": 40,
"height": 40,
"weight": 12,
"quantity": 40,
"rotation": "upright"
}
],
"options": {
"packing_mode": "auto"
}
}),
});
const data = await res.json();
console.log(res.status, data);import os
import requests
response = requests.post(
"https://runner.cargoduo.com/v1/pack",
headers={"Authorization": f"Bearer {os.environ['CARGODUO_API_KEY']}", "Idempotency-Key": "order-1042-v1"},
params={
"wait": 60,
},
json={
"reference": "order-1042",
"vehicles": [
{
"id": "trailer",
"type": "trailer",
"name": "13.6 m trailer",
"length": 1360,
"width": 245,
"height": 270,
"max_weight": 24000,
},
],
"items": [
{
"id": "pallet-eu",
"label": "Euro pallet",
"length": 120,
"width": 80,
"height": 140,
"weight": 450,
"quantity": 18,
"stackable": False,
},
{
"id": "carton-a",
"label": "Carton A",
"length": 60,
"width": 40,
"height": 40,
"weight": 12,
"quantity": 40,
"rotation": "upright",
},
],
"options": {
"packing_mode": "auto",
},
},
)
print(response.status_code, response.json())Xong kịp: 200, status: "succeeded", sơ đồ nằm trong result. Vẫn đang chạy: 202, chuyển sang bước 3.
Gọi định kỳ cho đến khi kết thúc
curl "https://runner.cargoduo.com/v1/jobs/$JOB_ID?include=result" \
-H "Authorization: Bearer $CARGODUO_API_KEY"async function waitForJob(job) {
while (job.status === "queued" || job.status === "running") {
await new Promise((r) => setTimeout(r, 2000));
const res = await fetch(`https://runner.cargoduo.com/v1/jobs/${job.id}?include=result`, {
headers: { Authorization: `Bearer ${process.env.CARGODUO_API_KEY}` },
});
job = await res.json();
}
return job;
}import os, time, requests
def wait_for_job(job):
headers = {"Authorization": f"Bearer {os.environ['CARGODUO_API_KEY']}"}
while job["status"] in ("queued", "running"):
time.sleep(2)
job = requests.get(f"https://runner.cargoduo.com/v1/jobs/{job['id']}", params={"include": "result"}, headers=headers).json()
return jobĐọc sơ đồ
| Trường | Nội dung |
|---|---|
result.vehicles[].placements[] | Vị trí, kích thước, hướng đặt và step xếp hàng của từng kiện hàng |
result.unplaced[] | Các kiện hàng không xếp vừa, kèm reason |
cost.credits | Số credit tác vụ đã bị trừ |
pdf_url | Liên kết để tạo PDF sơ đồ xếp hàng |
POST /v1/estimate kiểm tra và báo giá cùng nội dung đó miễn phí.