Upsert klienta
Dokumentacja poglądowa / kontrakt symulowany (draft). Schematy i przykłady odzwierciedlają zaplanowane Commerce API v1 — wartości finalne potwierdzimy przy zamrożeniu kontraktu produkcyjnego.
PUT /customers/{externalCustomerId}
Opis
Profil, locale BCP 47 i dowodem zgody. Base URL: https://api.callbotagent.ai/api/v1/commerce.
Wymagany scope
customers:write
Nagłówki
| Nagłówek | Wartość | Wymagany |
|---|---|---|
Content-Type |
application/json (gdy body) |
przy body |
X-CBA-Key-Id |
identyfikator klucza (w przykładach: cba_test_••••••••) |
tak |
X-CBA-Timestamp |
RFC 3339 UTC | tak |
X-CBA-Nonce |
unikalny nonce w oknie 300 s | tak |
X-CBA-Content-SHA256 |
SHA-256 hex surowego body (e3b0c44… dla pustego) |
tak |
X-CBA-Signature |
hmac-sha256=<hex> |
tak |
Idempotency-Key |
klucz idempotencji | mutacje: tak |
Parametry body
| Pole | Typ | Wymagane | Opis |
|---|---|---|---|
phone |
string | tak | E.164 |
locale |
string | tak | BCP 47, np. pl-PL |
consent.status |
enum | tak | granted |
consent.proof |
object | warunkowo | Wymagany przy granted |
source_version |
string | tak | Wersja źródła |
Przykład żądania
curl -X PUT https://api.callbotagent.ai/api/v1/commerce/customers/CUSTOMER-8821 \
-H "X-CBA-Key-Id: cba_test_••••••••" \
-H "X-CBA-Timestamp: 2026-07-11T10:00:00Z" \
-H "X-CBA-Nonce: n_8f3a2c1b" \
-H "X-CBA-Content-SHA256: <sha256-body>" \
-H "X-CBA-Signature: hmac-sha256=<hex>" \
-H "Idempotency-Key: idem-customers-externalCustomerId-put" \
-H "Content-Type: application/json" \
-d '{"phone":"+48512123456","locale":"pl-PL","consent":{"status":"granted","proof":{"source":"checkout_optin","reference":"form-2026-07-09-2231","collected_at":"2026-07-09T22:31:07Z"}},"source_version":"2026-07-11T09:00:00Z"}'const res = await fetch("https://api.callbotagent.ai/api/v1/commerce/customers/CUSTOMER-8821", {
method: "PUT",
headers: {
"X-CBA-Key-Id": "cba_test_••••••••",
"X-CBA-Timestamp": "2026-07-11T10:00:00Z",
"X-CBA-Nonce": "n_8f3a2c1b",
"X-CBA-Content-SHA256": "<sha256-body>",
"X-CBA-Signature": "hmac-sha256=<hex>",
"Idempotency-Key": "idem-customers-externalCustomerId-put",
"Content-Type": "application/json",
},
body: JSON.stringify({"phone":"+48512123456","locale":"pl-PL","consent":{"status":"granted","proof":{"source":"checkout_optin","reference":"form-2026-07-09-2231","collected_at":"2026-07-09T22:31:07Z"}},"source_version":"2026-07-11T09:00:00Z"}),
});
const data = await res.json();Przykładowa odpowiedź
{
"external_customer_id": "CUSTOMER-8821",
"outcome": "upserted",
"consent": {
"status": "granted"
}
}
Możliwe błędy
| Status | code |
Znaczenie |
|---|---|---|
| 401 | invalid_signature / expired_timestamp / replay_nonce |
HMAC / okno replay |
| 403 | insufficient_scope |
brak wymaganego scope |
| 404 | resource_not_found |
zasób niedostępny dla principal |
| 409 | idempotency_key_reused / stale_source_version |
konflikt idempotencji / wersji |
| 422 | validation_failed |
body nie spełnia schematu / invariants |
| 429 | rate_limited |
limity — patrz Retry-After |