PC

PostCargo REST API

Documentatie completa · v1.0 · Production-ready

API-ul PostCargo permite oricarui magazin online sau ERP sa integreze direct serviciile noastre de curierat: calcul preturi pe 12 curieri, generare AWB automata, tracking live, webhooks pentru status updates si retururi. Foloseste-l prin pluginuri oficiale (WooCommerce, Shopify) sau direct prin REST.

12
curieri integrati
200ms
latenta medie
99.9%
uptime
Base URL
https://api.postcargo.ro

Cele mai populare endpoint-uri

Autentificare

API-ul foloseste doua tipuri de autentificare:

1

X-API-Key

Pentru integrari (WooCommerce, ERP, scripts). O cheie pe integrare, revocabila oricand.

X-API-Key: pcg_live_xxxxxxxxxxxxxxxx
2

Bearer JWT

Pentru actiuni administrative (gestionare chei, setari tenant). Obtinut prin login.

Authorization: Bearer eyJhbGc...
Ambele in acelasi request — pentru operatiuni administrative care folosesc si X-API-Key, trimite ambele headere simultan. JWT autentifica utilizatorul, X-API-Key identifica integrarea.

Format raspuns

Toate raspunsurile au structura:

{
  "success": true,
  "data": { ... },
  "meta": { "page": 1, "total": 42 }
}

Erori:

{
  "success": false,
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Missing required field: weight"
  }
}

Coduri eroare

HTTP Code Cauza
400VALIDATION_ERRORCamp lipsa sau invalid
401UNAUTHORIZEDCheie API invalida sau expirata
403FORBIDDENPermisiune insuficienta
404NOT_FOUNDResursa inexistenta
429RATE_LIMITEDPrea multe cereri (vezi headerul Retry-After)
500INTERNAL_ERROREroare server (logata pe partea noastra)
503COURIER_UNAVAILABLEAPI curier offline temporar

Rate limiting

Limita implicita: 100 cereri / minut per cheie API. Headerele de raspuns:

X-RateLimit-Limit: 100
X-RateLimit-Remaining: 87
X-RateLimit-Reset: 1714650000
Retry-After: 12

Limita poate fi crescuta pentru clientii cu volum mare. Contact: suport@postcargo.ro

Permisiuni

Cheile API pot avea permisiuni granulare. Implicit, cheile noi au ["*"] (acces complet).

pricing:readCalculeaza preturi
shipments:createCreeaza expediere
shipments:readCiteste expedieri
shipments:cancelAnuleaza expediere
awb:createGenereaza AWB
awb:readDescarca AWB PDF
tracking:readTracking
webhooks:manageWebhooks
api_keys:manageGestioneaza chei (necesita JWT)
tenant:manageSetari cont (necesita JWT)

Auth & Conturi

POST /v1/auth/register Public

Creeaza un cont nou + tenant + prima cheie API. Returneaza JWT + cheia API (afisata o singura data).

Body

{
  "tenant_name": "Magazinul Meu SRL",
  "email": "owner@magazin.ro",
  "password": "parola_min_8",
  "name": "Ion Popescu"
}

Response 201

{
  "success": true,
  "data": {
    "user": { "id": 1, "email": "owner@magazin.ro", "name": "Ion Popescu" },
    "tenant": { "id": 1, "name": "Magazinul Meu SRL", "plan": "free" },
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "refresh_token": "rfk_...",
    "api_key": "pcg_live_a1b2c3d4e5..."
  }
}
POST /v1/auth/login Public

Login cu email + parola. Returneaza JWT + refresh token.

curl -X POST https://api.postcargo.ro/v1/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email":"owner@magazin.ro","password":"parola"}'
POST /v1/auth/refresh

Reinnoieste JWT folosind refresh token.

{ "refresh_token": "rfk_..." }
GET /v1/auth/api-keys JWT + API Key

Listeaza toate cheile API ale tenant-ului — cu request_count + last_used_at + last_used_ip.

{
  "success": true,
  "data": [
    {
      "id": 1,
      "key_prefix": "pcg_live_a1b2",
      "label": "WooCommerce - Magazin principal",
      "permissions": ["*"],
      "is_active": true,
      "last_used_at": "2026-05-03T20:30:12+03:00",
      "last_used_ip": "82.77.123.45",
      "request_count": 1432,
      "expires_at": null,
      "created_at": "2026-05-01T18:00:00+03:00"
    }
  ]
}
POST /v1/auth/api-keys

Genereaza o cheie noua. Cheia complet apare o singura data in raspuns; salveaza-o.

// Body
{
  "label": "WooCommerce - magazin nou",
  "permissions": ["pricing:read", "shipments:create", "awb:create"],
  "expires_in_days": 365
}

// Response
{
  "success": true,
  "data": {
    "id": 5,
    "label": "WooCommerce - magazin nou",
    "api_key": "pcg_live_xxxxxxxxxxxxxxxxxxxx",
    "key_prefix": "pcg_live_xxxx"
  }
}
GET /v1/auth/api-keys/{id}/logs

Loguri detaliate pe o cheie. Filtre disponibile: ?page=1&per_page=50&status=200&platform=woocommerce&from=2026-05-01&to=2026-05-31

{
  "success": true,
  "data": {
    "key": { "id": 1, "label": "...", "request_count": 1432 },
    "stats_24h": { "total": 245, "success": 240, "errors": 5, "avg_ms": 187 },
    "logs": [
      {
        "id": 9876, "method": "POST", "endpoint": "/v1/pricing/quote",
        "status_code": 200, "duration_ms": 215, "ip": "82.77.x",
        "source_platform": "woocommerce", "created_at": "..."
      }
    ]
  },
  "meta": { "page": 1, "per_page": 50, "total": 1432, "total_pages": 29 }
}
GET /v1/auth/api-keys/usage

Stats agregate (toate cheile, ultimele 7-90 zile). ?days=7

{
  "data": {
    "totals": { "total": 12450, "success": 12200, "errors": 250, "avg_ms": 195 },
    "by_day": [{ "day": "2026-05-01", "total": 1820, "success": 1810, "errors": 10 }],
    "by_platform": [{ "platform": "woocommerce", "total": 11230 }],
    "top_endpoints": [{ "endpoint": "/v1/pricing/quote", "total": 6420 }]
  }
}
DELETE /v1/auth/api-keys/{id}

Revoca cheia. Integrarea care o foloseste va inceta sa functioneze imediat.

Public (fara auth)

GET /health Public
{ "success": true, "data": { "status": "ok", "version": "1.0.0", "php": "8.3.30" } }
GET /v1/couriers Public

Lista publica a celor 12 curieri integrati (logo, descriere, pret pornire, features).

Pricing

POST /v1/pricing/quote

Calculeaza pretul pentru toti curierii activi simultan. Recomandat pentru checkout in WooCommerce/Shopify.

Body

{
  "from": { "city": "Bucuresti", "county": "Bucuresti", "postcode": "010101" },
  "to":   { "city": "Cluj-Napoca", "county": "Cluj", "postcode": "400001" },
  "package": {
    "type": "colet",
    "weight": 2.5,
    "length": 30, "width": 20, "height": 15,
    "value_declared": 250,
    "cod_amount": 0
  },
  "options": {
    "saturday_delivery": false,
    "open_on_delivery": false,
    "insurance": true
  }
}

Response

{
  "success": true,
  "data": [
    {
      "courier": "fan-courier",
      "courier_name": "FAN Courier",
      "price": 28.50,
      "price_with_vat": 33.92,
      "estimated_days": "1-2 zile",
      "logo": "https://api.postcargo.ro/assets/couriers/fan-courier.svg"
    },
    {
      "courier": "cargus",
      "courier_name": "Urgent Cargus",
      "price": 25.20,
      "price_with_vat": 30.50,
      "estimated_days": "1-3 zile"
    }
  ]
}
POST /v1/pricing/calculate

Pret pentru un singur curier specific. Body identic cu /quote, plus "courier": "fan-courier".

Expedieri

POST /v1/shipments

Creeaza expediere fara generare AWB (status: draft). AWB se genereaza separat (vezi /v1/awb).

{
  "courier_code": "fan-courier",
  "external_id": "wc_order_1234",
  "sender": {
    "name": "Magazinul Meu", "phone": "0712345678",
    "city": "Bucuresti", "county": "Bucuresti",
    "address": "Str Exemplu 10", "postcode": "010101"
  },
  "recipient": {
    "name": "Maria Popescu", "phone": "0723456789",
    "city": "Cluj-Napoca", "county": "Cluj",
    "address": "Str Aurel Vlaicu 25", "postcode": "400001"
  },
  "package": {
    "type": "colet", "weight": 2.5,
    "length": 30, "width": 20, "height": 15,
    "value_declared": 250,
    "cod_amount": 0,
    "content": "Carti, articole personale"
  }
}
GET /v1/shipments

Filtre: ?status=delivered&courier=fan-courier&page=1&per_page=50&from=2026-05-01

GET /v1/shipments/{id}

Detaliile complete (sender, recipient, package, awb, tracking history).

POST /v1/shipments/{id}/cancel

Anuleaza la curier (daca AWB nu e inca preluat). Body optional: {"reason": "Cumparator a anulat"}

GET /v1/shipments/{id}/tracking

Tracking events live de la curier.

{
  "data": {
    "awb_number": "1234567890",
    "status": "in_transit",
    "events": [
      { "date": "2026-05-03T09:15:00", "status": "preluat", "location": "Bucuresti" },
      { "date": "2026-05-03T18:30:00", "status": "in_tranzit", "location": "Cluj-Napoca" }
    ]
  }
}

AWB (Air Waybill)

POST /v1/awb/{shipment_id}

Genereaza AWB la curierul ales. Returneaza numarul AWB + URL PDF.

{
  "data": {
    "awb_number": "1234567890",
    "courier": "fan-courier",
    "pdf_url": "https://api.postcargo.ro/v1/awb/1234567890/pdf",
    "tracking_url": "https://www.fancourier.ro/awb-tracking/?awb=1234567890"
  }
}
GET /v1/awb/{id}/pdf

Returneaza PDF binar al AWB-ului. Headers: Content-Type: application/pdf.

Tenant (cont)

GET /v1/tenant/couriers

Lista celor 12 curieri PostCargo cu detalii (logo, descriere, features, pret pornire) si flag is_enabled pentru tenant.

Important: nu trebuie sa-ti pui credentialele curierilor. Folosesti contractele PostCargo automat — preturi negociate, AWB direct prin platforma noastra.
PUT /v1/tenant/couriers/{code}

Activeaza/dezactiveaza un curier pentru contul tau. Body: {"is_active": true}

GET /v1/tenant/stats

Stats agregate: total expedieri, by status, by courier, ultimele 5.

Webhooks

GET /v1/webhooks

Lista webhook-urilor configurate.

POST /v1/webhooks

Configureaza un webhook care primeste evenimente (shipment.created, shipment.delivered, awb.generated, etc).

{
  "url": "https://magazin.ro/postcargo-webhook",
  "events": ["shipment.delivered", "shipment.cancelled"],
  "secret": "secret_pentru_HMAC"
}

Integrari (publice)

GET /v1/integrations Public

Lista pluginurilor disponibile (WooCommerce activ; Shopify, PrestaShop in lucru).

GET /v1/integrations/woocommerce/info Public

Versiune curenta plugin, cerinte WP/WooCommerce, marime, data ultimului build.

GET /v1/integrations/woocommerce/download Public

Descarca postcargo-shipping.zip direct. Auto-build cand sursa devine mai noua decat .zip-ul cached.

Descarca acum (.zip)