在 设置 → API 与集成 点击“新密钥”并选择“仅发布行程”。从一个密钥开始 测试: 您发布的内容不会出现在交易平台上。
请将密钥放入环境变量,而不是代码中:
export GOCARGO_API_KEY="gc_test_..."curl https://gocargo.ro/api/v1/me \
-H "Authorization: Bearer $GOCARGO_API_KEY"响应会显示公司、密钥权限和请求限制。
发送货源,附带 external_id = 您 TMS 中的 ID。如果重新发送,我们会更新而不是新建(upsert),因此同步非常简单。
您的货源列表:
curl "https://gocargo.ro/api/v1/loads?limit=20" \
-H "Authorization: Bearer $GOCARGO_API_KEY"curl -X POST https://gocargo.ro/api/v1/loads \
-H "Authorization: Bearer $GOCARGO_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{
"external_id": "TMS-10045",
"origin_country": "RO",
"origin_city": "Cluj-Napoca",
"dest_country": "DE",
"dest_city": "Stuttgart",
"cargo": "Piese auto, 12 paleti",
"loading_date": "2026-12-03",
"vehicle_kind": "prelata",
"weight_kg": 8000,
"price": 1450,
"currency": "EUR"
}'每个请求都带有标头 Authorization: Bearer gc_live_… (或 gc_test_…)。基础地址为 https://gocargo.ro/api/v1。仅限 HTTPS。
X-Request-Id; 向我们寻求帮助时请一并发送。缺少所需权限的请求将收到 403 scope_missing.
| 权限 | 允许的操作 |
|---|---|
loads:read | 读取公司的货源 |
loads:write | 发布、修改和撤下货源 |
trucks:read | 读取公司的空闲卡车 |
trucks:write | 发布、修改和撤下空闲卡车 |
orders:read | 读取订单 |
orders:write | 更改订单状态并发送 GPS 位置 |
marketplace:read | 在公开交易平台中搜索(货源和卡车) |
webhooks:manage | 通过 API 管理 webhook |
export:read | 导出数据(Business 和 Enterprise 套餐) |
HTTP/1.1 400 Bad Request
X-Request-Id: 5f0c2e7a9b1d4c3e
Content-Type: application/json
{
"error": {
"code": "invalid_request",
"message": "Datele trimise nu sunt valide.",
"fields": { "loading_date": "Data de încărcare nu poate fi în trecut." }
}
}| HTTP | 代码 | 何时 |
|---|---|---|
| 400 | invalid_request | 数据无效;各字段详情见“fields” |
| 401 | unauthorized | 密钥缺失、错误或已撤销 |
| 401 | key_expired | 密钥已过期 |
| 402 | plan_required | 该功能不包含在公司当前套餐中 |
| 403 | forbidden | 贵公司无权执行此操作 |
| 403 | scope_missing | 密钥缺少所需权限(消息中会指明) |
| 403 | ip_not_allowed | 请求来自不在密钥白名单中的 IP |
| 404 | not_found | 资源不存在或不属于该公司 |
| 409 | conflict | 状态不兼容,或 Idempotency-Key 被不同请求体重复使用 |
| 429 | rate_limited | 请求过多;请按 Retry-After 所示时间等待 |
| 429 | quota_exceeded | 公司的每月请求配额已用完 |
| 500 | server_error | 我们这边出错了;请重试并将 X-Request-Id 发给我们 |
| 套餐 / 许可 | 每个密钥每分钟请求数 | 每家公司每月请求数 | 域名 |
|---|---|---|---|
| Pro | 60 | 50.000 | 1 |
| Business | 300 | 300.000 | 1 |
| Enterprise | 1200 | 2.000.000 | 3 |
| 软件集成商 | 600 | 1.000.000 | 10 |
| 交易平台合作伙伴 / 聚合器 | 1200 | 5.000.000 | 25 |
X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset。超出限制:返回 429,附带 Retry-After (secunde).X-Quota-Limit 和 X-Quota-Remaining;会消耗所有密钥,包括测试密钥。附加套餐和商业许可: API 价格.?limit=100&cursor=…, 回复 {data, next_cursor}。同步请使用 updated_since.curl -X POST https://gocargo.ro/api/v1/loads/bulk \
-H "Authorization: Bearer $GOCARGO_API_KEY" \
-H "Content-Type: application/json" \
-d '{"items": [ {...}, {...} ]}'
# Răspuns: fiecare element are rezultatul lui
{"results": [
{"index": 0, "ok": true, "ref": "GC1A2B3C4D"},
{"index": 1, "ok": false, "error": {"code": "invalid_request", "message": "..."}}
]}任意 POST 发送标头 Idempotency-Key 使用唯一值(例如 UUID)。如果网络中断,使用相同的值重试,将得到完全相同的响应,不会产生第二批货源。响应保留 24 小时。相同的值配不同的请求体 → 409 conflict.
请在以下位置添加 HTTPS URL: 设置 → API 与集成 → Webhooks (或通过 POST /webhooks)并选择事件。密钥 whsec_… 仅显示一次。
| 事件 | 何时 |
|---|---|
load.created | 一个货源已发布 |
load.updated | 一个货源已被修改 |
load.booked | 一个货源已被预订 |
load.withdrawn | 一个货源已被撤下 |
quote.received | 您收到了一个价格报价 |
order.created | 已创建订单 |
order.status_changed | 订单状态已变更 |
order.document_added | 订单已添加文档(CMR、发票) |
order.position_updated | 卡车位置已更新 |
message.received | 您收到了一条消息 |
POST /gocargo/webhook HTTP/1.1
Content-Type: application/json
GoCargo-Signature: t=1760180000,v1=8f3c...e91a
{
"id": "evt_2b7f0c9e1a4d",
"type": "order.status_changed",
"created_at": "2026-10-11T09:30:00Z",
"data": { ... }
}id 以忽略重复项。标头 GoCargo-Signature: t=<unix>,v1=<hex>, 其中 v1 = 使用 webhook 密钥的 HMAC-SHA256(完整密钥,含 whsec_) 在 {t}.{corpul brut}。请拒绝超过 5 分钟的签名。
# pip install flask
import hashlib
import hmac
import os
import time
from flask import Flask, abort, request
SECRET = os.environ["GOCARGO_WEBHOOK_SECRET"] # whsec_..., întreg
app = Flask(__name__)
def verify(header: str, body: bytes, tolerance: int = 300) -> bool:
parts = dict(p.strip().split("=", 1) for p in header.split(",") if "=" in p)
t, sig = parts.get("t", ""), parts.get("v1", "")
if not t.isdigit() or abs(time.time() - int(t)) > tolerance:
return False
expected = hmac.new(SECRET.encode(), t.encode() + b"." + body, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, sig)
@app.post("/gocargo/webhook")
def webhook():
# Semnătura se calculează pe corpul BRUT, exact cum a sosit.
if not verify(request.headers.get("GoCargo-Signature", ""), request.get_data()):
abort(400)
event = request.get_json()
print(event["type"], event["data"])
return "", 204如果创建时勾选“必须 HMAC 签名”,您还会获得一个签名密钥。每个请求还必须带有以下标头 X-GoCargo-Timestamp (unix 秒)和 X-GoCargo-Signature = 十六进制 HMAC-SHA256,作用于 {timestamp}.{METODĂ}.{cale}.{corp}.
cale 是服务器上的完整路径加上您发送的确切查询(如有),例如 /api/v1/loads sau /api/v1/loads?status=active。对于 GET,请求体为空(消息以“.”结尾)。import hashlib
import hmac
import json
import os
import time
import requests
ORIGIN = "https://gocargo.ro"
PATH = "/api/v1/loads"
KEY = os.environ["GOCARGO_API_KEY"]
SIGNING_SECRET = os.environ["GOCARGO_SIGNING_SECRET"]
body = json.dumps({"origin_city": "Cluj-Napoca", "dest_country": "DE", "dest_city": "Stuttgart",
"cargo": "Piese auto", "loading_date": "2026-12-03"}).encode()
ts = str(int(time.time()))
message = ts.encode() + b".POST." + PATH.encode() + b"." + body
signature = hmac.new(SIGNING_SECRET.encode(), message, hashlib.sha256).hexdigest()
r = requests.post(ORIGIN + PATH, data=body, timeout=30, headers={
"Authorization": "Bearer " + KEY,
"Content-Type": "application/json",
"X-GoCargo-Timestamp": ts,
"X-GoCargo-Signature": signature,
})
print(r.status_code, r.text)GET /export/{set}?format=csv|xlsx|json&from=AAAA-LL-ZZ&to=AAAA-LL-ZZ, 集合 ∈ loads, trucks, orders, quotes, reviews。该密钥需要 export:read。每次请求最多 50.000 行和 366 天。CSV 采用 UTF-8 BOM 和“;”分隔符,以便在 Excel 中正确打开。
curl -o comenzi.xlsx \
"https://gocargo.ro/api/v1/export/orders?format=xlsx&from=2026-01-01&to=2026-06-30" \
-H "Authorization: Bearer $GOCARGO_API_KEY"没有验证码: 设置 → 数据导出.
切勿将 API 密钥放入浏览器端的 HTML 或 JavaScript 中。 任何打开该页面的人都能看到它(View Source、DevTools),并可以以贵公司名义发布。密钥只保存在服务器上:表单提交到您自己的脚本,再由脚本调用 GoCargo。
<!-- formularul din site: trimite la scriptul PHP de pe serverul vostru, NU la GoCargo -->
<form method="post" action="/publica.php">
<input name="origin_city" placeholder="De la" required>
<input name="dest_city" placeholder="Până la" required>
<input name="dest_country" value="RO" maxlength="2">
<input name="cargo" placeholder="Marfă" required>
<input name="loading_date" type="date" required>
<button>Publică pe GoCargo</button>
</form><?php // publica.php — cheia stă doar aici, pe server
$key = getenv('GOCARGO_API_KEY');
$load = [
'origin_country' => 'RO', 'origin_city' => $_POST['origin_city'] ?? '',
'dest_country' => strtoupper($_POST['dest_country'] ?? 'RO'), 'dest_city' => $_POST['dest_city'] ?? '',
'cargo' => $_POST['cargo'] ?? '', 'loading_date' => $_POST['loading_date'] ?? '',
];
$ch = curl_init('https://gocargo.ro/api/v1/loads');
curl_setopt_array($ch, [CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $key, 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode($load, JSON_UNESCAPED_UNICODE)]);
$res = curl_exec($ch);
http_response_code(curl_getinfo($ch, CURLINFO_HTTP_CODE) ?: 502);
header('Content-Type: application/json');
echo $res;请保护该脚本(仅限您网站的已登录用户,CSRF 令牌)并设置 GOCARGO_API_KEY 在服务器配置中,而不是在文件中。最好使用仅具有以下权限的密钥 loads:write 以及对服务器 IP 的限制。
API 包含在 Pro、Business 和 Enterprise 套餐中。可先使用测试密钥,零风险。