Riferimento
Tutte le rotte, con i campi, gli esempi e la prova dal vivo. Indirizzo: https://api.packhub.it/v1. Scrivi la tua chiave nel riquadro a sinistra per provarle.
Account
/v1/accountProva la chiave
Nome dell’account, credito disponibile, tipo della chiave e numero di contratti. Gratis.
curl -X GET "https://api.packhub.it/v1/account" \
-H "Authorization: Bearer $PACKHUB_KEY"const res = await fetch('https://api.packhub.it/v1/account', {
method: 'GET',
headers: {
Authorization: `Bearer ${process.env.PACKHUB_KEY}`,
},
});
const data = await res.json();
if (!res.ok) throw new Error(`${data.error.code}: ${data.error.message}`);
console.log(data);<?php
$ch = curl_init('https://api.packhub.it/v1/account');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('PACKHUB_KEY')],
]);
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$data = json_decode($response, true);
if ($status >= 400) {
throw new Exception($data['error']['code'] . ': ' . $data['error']['message']);
}
Campi della risposta
| Campo | Tipo | Obbl. | Descrizione |
|---|---|---|---|
name | testo | sì | Nome dell’account: la ragione sociale, o l’email se manca. |
email | testo | sì | |
currency | "EUR" | sì | |
wallet | oggetto | sì | Il credito del cliente. Finito il disponibile, la creazione risponde 402 INSUFFICIENT_FUNDS. |
wallet.balanceCents | intero min -9007199254740991, max 9007199254740991 | sì | Saldo del wallet. |
wallet.creditLimitCents | intero min 0, max 9007199254740991 | sì | Fido concesso: si può spendere fino a saldo più fido. |
wallet.availableCents | intero min -9007199254740991, max 9007199254740991 | sì | Disponibile per nuove spedizioni: saldo più fido. |
contractsCount | intero min 0, max 9007199254740991 | sì | Contratti che questa chiave può usare. |
key | oggetto | sì | |
key.mode | "live" | "test" | sì | live crea spedizioni vere; test solo spedizioni di prova. |
key.label | testo | sì | |
key.prefix | testo | sì | |
key.allContracts | sì/no | sì | false = la chiave è limitata ad alcuni contratti. |
rateLimitPerMinute | intero min 1, max 9007199254740991 | sì | Richieste al minuto per chiave. |
Risposte
200L’account.401Chiave mancante, non valida o revocata (UNAUTHENTICATED).429Troppe richieste (RATE_LIMITED): aspetta i secondi diRetry-After.
/v1/contractsI contratti della chiave
I contratti con cui la chiave spedisce: corriere, nome del servizio, servizi accessori, colli massimi, misure obbligatorie, ritiro e come si annulla. L’id va in contractId.
curl -X GET "https://api.packhub.it/v1/contracts" \
-H "Authorization: Bearer $PACKHUB_KEY"const res = await fetch('https://api.packhub.it/v1/contracts', {
method: 'GET',
headers: {
Authorization: `Bearer ${process.env.PACKHUB_KEY}`,
},
});
const data = await res.json();
if (!res.ok) throw new Error(`${data.error.code}: ${data.error.message}`);
console.log(data);<?php
$ch = curl_init('https://api.packhub.it/v1/contracts');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('PACKHUB_KEY')],
]);
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$data = json_decode($response, true);
if ($status >= 400) {
throw new Exception($data['error']['code'] . ': ' . $data['error']['message']);
}
Campi della risposta
| Campo | Tipo | Obbl. | Descrizione |
|---|---|---|---|
items | array di oggetto | sì | |
items[].id | testo (uuid) | sì | Da usare come contractId nel preventivo e nella creazione. |
items[].carrier | testo | sì | Corriere che consegna, per esempio BRT, GLS, POSTE, SDA. |
items[].name | testo | sì | Nome del servizio. |
items[].services | array di oggetto | sì | Servizi accessori che si possono chiedere, con il codice da mandare in services. |
items[].services[].code | testo | sì | |
items[].services[].label | testo | sì | |
items[].services[].description | testo | sì | |
items[].services[].params | array di oggetto | ||
items[].services[].params[].name | testo | sì | |
items[].services[].params[].label | testo | sì | |
items[].services[].params[].type | "text" | "date" | "select" | "weekdays" | sì | |
items[].services[].params[].required | sì/no | sì | |
items[].services[].params[].options | array di oggetto | ||
items[].services[].params[].maxLength | intero min 1, max 9007199254740991 | ||
items[].services[].params[].help | testo | ||
items[].deliveryModes | array di "ADDRESS" | "PARCEL_SHOP" | "LOCKER" | "POST_OFFICE" | sì | Dove consegna. Nel primo pezzo dell’API si spedisce solo all’indirizzo (ADDRESS). |
items[].maxParcels | intero min 1, max 9007199254740991 | sì | Colli al massimo per spedizione. |
items[].requiresDimensions | sì/no | sì | Il corriere vuole lunghezza, larghezza e altezza di ogni collo. |
items[].scope | "domestic" | "international" | sì | Italia o estero. Nel primo pezzo dell’API solo Italia. |
items[].pickup | sì/no | sì | Si può chiedere il ritiro al domicilio del mittente alla creazione. |
items[].cancellation | "carrier" | "packhub" | "none" | sì | carrier: l’annullamento arriva al corriere. packhub: il corriere non ha l’annullamento automatico, la spedizione si annulla solo in PackHub con il rimborso (se il pacco viene consegnato lo stesso, si riaddebita). none: non si annulla. |
items[].senderFromContract | "company" | "custom" o null | sì | Il mittente che arriva al corriere viene dal contratto (indirizzo dell’azienda o uno scritto nel contratto). null = quello della spedizione. |
items[].lockOrigin | sì/no | sì | Il mittente deve partire dall’indirizzo del profilo. |
Risposte
200I contratti.401Chiave mancante, non valida o revocata (UNAUTHENTICATED).429Troppe richieste (RATE_LIMITED): aspetta i secondi diRetry-After.
Preventivi
/v1/ratesCalcola il prezzo
Un prezzo per ogni contratto della chiave, o solo per contractId. Un contratto che non può fare questa spedizione torna con available: false e il motivo, senza far fallire gli altri. Non crea niente e non addebita niente.
Corpo della richiesta
| Campo | Tipo | Obbl. | Descrizione |
|---|---|---|---|
contractId | testo (uuid) | Un solo contratto. Assente = tutti quelli della chiave. | |
destination | oggetto | sì | |
destination.zipCode | testo | sì | CAP del destinatario. |
destination.city | testo da 1 caratteri, fino a 35 caratteri | sì | Comune del destinatario. |
parcels | array di oggetto fino a 10 elementi | sì | Da 1 a 10 colli. |
parcels[].weightKg | numero > 0, max 999.99 | sì | |
parcels[].lengthCm | numero > 0, max 999 | ||
parcels[].widthCm | numero > 0, max 999 | ||
parcels[].heightCm | numero > 0, max 999 | ||
codAmountCents | intero min 0, max 9007199254740991 | Contrassegno da incassare, in centesimi. | |
insuranceAmountCents | intero min 0, max 9007199254740991 | Valore da assicurare, in centesimi. | |
services | array di testo fino a 10 elementi | Codici dei servizi accessori (services del contratto). |
curl -X POST "https://api.packhub.it/v1/rates" \
-H "Authorization: Bearer $PACKHUB_KEY" \
-H "Content-Type: application/json" \
-d '{
"destination": {
"zipCode": "20121",
"city": "Milano"
},
"parcels": [
{
"weightKg": 2.5,
"lengthCm": 30,
"widthCm": 20,
"heightCm": 15
}
]
}'const res = await fetch('https://api.packhub.it/v1/rates', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.PACKHUB_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"destination": {
"zipCode": "20121",
"city": "Milano"
},
"parcels": [
{
"weightKg": 2.5,
"lengthCm": 30,
"widthCm": 20,
"heightCm": 15
}
]
}),
});
const data = await res.json();
if (!res.ok) throw new Error(`${data.error.code}: ${data.error.message}`);
console.log(data);<?php
$ch = curl_init('https://api.packhub.it/v1/rates');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('PACKHUB_KEY'), 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode([
'destination' => [
'zipCode' => '20121',
'city' => 'Milano',
],
'parcels' => [
[
'weightKg' => 2.5,
'lengthCm' => 30,
'widthCm' => 20,
'heightCm' => 15,
],
],
]),
]);
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$data = json_decode($response, true);
if ($status >= 400) {
throw new Exception($data['error']['code'] . ': ' . $data['error']['message']);
}
Campi della risposta
| Campo | Tipo | Obbl. | Descrizione |
|---|---|---|---|
items | array di oggetto o oggetto | sì | |
items[].available | true | sì | |
items[].contractId | testo (uuid) | sì | |
items[].carrier | testo | sì | Corriere che consegna, per esempio BRT, GLS, POSTE, SDA. |
items[].name | testo | sì | |
items[].price | oggetto | sì | |
items[].price.currency | "EUR" | sì | |
items[].price.totalCents | intero min 0, max 9007199254740991 | sì | Totale della spedizione, senza il ritiro. |
items[].price.freightCents | intero min 0, max 9007199254740991 | sì | Nolo prima del carburante. |
items[].price.fuelCents | intero min 0, max 9007199254740991 | sì | Supplemento carburante. |
items[].price.codFeeCents | intero min 0, max 9007199254740991 | sì | Costo del contrassegno. |
items[].price.insuranceFeeCents | intero min 0, max 9007199254740991 | sì | Costo dell’assicurazione. |
items[].price.servicesCents | intero min 0, max 9007199254740991 | sì | Servizi accessori. |
items[].price.tailLiftCents | intero min 0, max 9007199254740991 | sì | Sponda idraulica. |
items[].price.oversizeCents | intero min 0, max 9007199254740991 | sì | Colli ingombranti. |
items[].price.services | array di oggetto | sì | |
items[].price.services[].code | testo | sì | |
items[].price.services[].label | testo | sì | |
items[].price.services[].cents | intero min 0, max 9007199254740991 | sì | |
items[].price.zone | "NATIONAL" | "SICILY" | "SARDINIA" | "MINOR_ISLANDS" | "INTERNATIONAL" | sì | |
items[].price.zoneName | testo | sì | |
items[].price.weight | oggetto | sì | |
items[].price.weight.actualKg | numero min 0 | sì | Peso reale. |
items[].price.weight.volumetricKg | numero min 0 | sì | Peso volumetrico (dalle misure). |
items[].price.weight.chargeableKg | numero min 0 | sì | Peso su cui si calcola il prezzo. |
items[].pickup | oggetto o oggetto | sì | |
items[].available | false | sì | |
items[].error | oggetto | sì | Perché questo contratto non spedisce questa spedizione. |
items[].error.code | testo | sì | |
items[].error.message | testo | sì | |
items[].error.details | oggetto |
Risposte
200I prezzi.400Richiesta non valida (VALIDATION_ERROR).401Chiave mancante, non valida o revocata (UNAUTHENTICATED).404Non trovato (NOT_FOUND).429Troppe richieste (RATE_LIMITED): aspetta i secondi diRetry-After.
Spedizioni
/v1/shipmentsCrea una spedizione
Crea la spedizione presso il corriere del contratto e addebita il prezzo sul tuo wallet. Con una chiave di prova la spedizione è finta: nessun corriere, nessun addebito, un’etichetta di prova e un tracking che avanza da solo. Il ritiro al domicilio si chiede solo qui, con pickup.date.
Parametri
| Nome | Dove | Obbl. | Descrizione |
|---|---|---|---|
Idempotency-Key | header | sì | Un valore tuo, unico per ogni spedizione (per esempio il numero d’ordine). Ripetere con lo stesso valore e gli stessi dati dà la stessa spedizione; con dati diversi, 409. |
Corpo della richiesta
| Campo | Tipo | Obbl. | Descrizione |
|---|---|---|---|
contractId | testo (uuid) | sì | Uno dei contratti di GET /v1/contracts. |
sender | oggetto | Mittente. Assente = il mittente del profilo. | |
sender.name | testo da 1 caratteri, fino a 70 caratteri | sì | |
sender.contactName | testo fino a 35 caratteri | ||
sender.street | testo da 1 caratteri, fino a 70 caratteri | sì | |
sender.houseNumber | testo fino a 10 caratteri | ||
sender.city | testo da 1 caratteri, fino a 35 caratteri | sì | |
sender.zipCode | testo | sì | |
sender.province | testo | sì | |
sender.country | "IT" predefinito "IT" | ||
sender.phone | testo | sì | |
sender.email | testo (email) | ||
sender.notes | testo fino a 140 caratteri | ||
recipient | oggetto | sì | Destinatario, in Italia. |
recipient.name | testo da 1 caratteri, fino a 70 caratteri | sì | |
recipient.contactName | testo fino a 35 caratteri | ||
recipient.street | testo da 1 caratteri, fino a 70 caratteri | sì | |
recipient.houseNumber | testo fino a 10 caratteri | ||
recipient.city | testo da 1 caratteri, fino a 35 caratteri | sì | |
recipient.zipCode | testo | sì | |
recipient.province | testo | sì | |
recipient.country | "IT" predefinito "IT" | ||
recipient.phone | testo | sì | |
recipient.email | testo (email) | ||
recipient.notes | testo fino a 140 caratteri | ||
parcels | array di oggetto fino a 10 elementi | sì | Da 1 a 10 colli. |
parcels[].weightKg | numero > 0, max 999.99 | sì | |
parcels[].lengthCm | numero > 0, max 999 | ||
parcels[].widthCm | numero > 0, max 999 | ||
parcels[].heightCm | numero > 0, max 999 | ||
cod | oggetto | Contrassegno: importo da incassare e come lo paga il destinatario. | |
cod.amountCents | intero min 1, max 9007199254740991 | sì | |
cod.paymentType | "CONTANTI" | "ASSEGNO_BANCARIO" | "ASSEGNO_CIRCOLARE" | sì | |
insurance | oggetto | Assicurazione: valore assicurato. | |
insurance.amountCents | intero min 1, max 9007199254740991 | sì | |
notes | testo fino a 140 caratteri | Note per il corriere. | |
services | array di testo fino a 10 elementi | Codici dei servizi accessori. | |
serviceParams | oggetto | Dati dei servizi scelti che ne hanno bisogno (params del servizio nel contratto). | |
reference | testo da 1 caratteri, fino a 30 caratteri | Riferimento del mittente, per esempio l’ordine. | |
pickup | oggetto | Ritiro al domicilio del mittente: da lunedì a venerdì, non festivi; oggi solo prima delle 9:30; al massimo 10 giorni lavorativi. Si chiede solo qui, alla creazione. | |
pickup.date | testo (date) | sì |
curl -X POST "https://api.packhub.it/v1/shipments" \
-H "Authorization: Bearer $PACKHUB_KEY" \
-H "Idempotency-Key: ORDINE-1001" \
-H "Content-Type: application/json" \
-d '{
"contractId": "00000000-0000-4000-8000-000000000000",
"recipient": {
"name": "Mario Rossi",
"street": "Via Roma",
"houseNumber": "10",
"city": "Milano",
"zipCode": "20121",
"province": "MI",
"phone": "3331234567",
"email": "mario.rossi@example.com"
},
"parcels": [
{
"weightKg": 2.5,
"lengthCm": 30,
"widthCm": 20,
"heightCm": 15
}
],
"reference": "ORDINE-1001"
}'const res = await fetch('https://api.packhub.it/v1/shipments', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.PACKHUB_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': 'ORDINE-1001',
},
body: JSON.stringify({
"contractId": "00000000-0000-4000-8000-000000000000",
"recipient": {
"name": "Mario Rossi",
"street": "Via Roma",
"houseNumber": "10",
"city": "Milano",
"zipCode": "20121",
"province": "MI",
"phone": "3331234567",
"email": "mario.rossi@example.com"
},
"parcels": [
{
"weightKg": 2.5,
"lengthCm": 30,
"widthCm": 20,
"heightCm": 15
}
],
"reference": "ORDINE-1001"
}),
});
const data = await res.json();
if (!res.ok) throw new Error(`${data.error.code}: ${data.error.message}`);
console.log(data);<?php
$ch = curl_init('https://api.packhub.it/v1/shipments');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('PACKHUB_KEY'), 'Content-Type: application/json', 'Idempotency-Key: ORDINE-1001'],
CURLOPT_POSTFIELDS => json_encode([
'contractId' => '00000000-0000-4000-8000-000000000000',
'recipient' => [
'name' => 'Mario Rossi',
'street' => 'Via Roma',
'houseNumber' => '10',
'city' => 'Milano',
'zipCode' => '20121',
'province' => 'MI',
'phone' => '3331234567',
'email' => 'mario.rossi@example.com',
],
'parcels' => [
[
'weightKg' => 2.5,
'lengthCm' => 30,
'widthCm' => 20,
'heightCm' => 15,
],
],
'reference' => 'ORDINE-1001',
]),
]);
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$data = json_decode($response, true);
if ($status >= 400) {
throw new Exception($data['error']['code'] . ': ' . $data['error']['message']);
}
Campi della risposta
| Campo | Tipo | Obbl. | Descrizione |
|---|---|---|---|
id | testo (uuid) | sì | Identificativo stabile della spedizione: il numero di tracking può cambiare. |
mode | "live" | "test" | sì | test per le spedizioni di prova. |
status | "creating" | "created" | "failed" | "cancelled" | sì | creating: in verifica (il corriere non ha dato un esito: non ripetere). created: creata. failed: rifiutata dal corriere, nessun addebito. cancelled: annullata e rimborsata. |
createdAt | testo (date-time) | sì | |
contractId | testo (uuid) | sì | |
carrier | testo | sì | Corriere che consegna, per esempio BRT, GLS, POSTE, SDA. |
contractName | testo | sì | |
trackingNumber | qualunque | sì | Numero di tracking. Su alcuni contratti nasce con un riferimento provvisorio di PackHub (PK…) e poi diventa quello del corriere: GET /v1/tracking/{numero} accetta tutti e due. |
trackingStatus | qualunque | sì | |
reference | qualunque | sì | |
recipient | oggetto | sì | |
recipient.name | testo | sì | |
recipient.contactName | testo | ||
recipient.street | testo | sì | |
recipient.houseNumber | testo | ||
recipient.city | testo | sì | |
recipient.zipCode | testo | sì | |
recipient.province | testo | ||
recipient.country | testo predefinito "IT" | sì | Codice ISO del paese, IT per l’Italia. |
recipient.territory | testo | ||
recipient.phone | testo | sì | |
recipient.email | testo | ||
recipient.notes | testo | ||
parcelsCount | intero min 1, max 9007199254740991 | sì | |
priceCents | intero min 0, max 9007199254740991 | sì | Quanto è stato addebitato per il trasporto. |
sender | oggetto | sì | |
sender.name | testo | sì | |
sender.contactName | testo | ||
sender.street | testo | sì | |
sender.houseNumber | testo | ||
sender.city | testo | sì | |
sender.zipCode | testo | sì | |
sender.province | testo | ||
sender.country | testo predefinito "IT" | sì | Codice ISO del paese, IT per l’Italia. |
sender.territory | testo | ||
sender.phone | testo | sì | |
sender.email | testo | ||
sender.notes | testo | ||
parcels | array di oggetto | sì | |
parcels[].weightKg | numero > 0, max 999.99 | sì | |
parcels[].lengthCm | numero > 0, max 999 | ||
parcels[].widthCm | numero > 0, max 999 | ||
parcels[].heightCm | numero > 0, max 999 | ||
codAmountCents | intero min 0, max 9007199254740991 | sì | |
insuranceAmountCents | intero min 0, max 9007199254740991 | sì | |
serviceParams | oggetto o null | sì | |
price | oggetto | sì | |
price.currency | "EUR" | sì | |
price.totalCents | intero min 0, max 9007199254740991 | sì | Totale della spedizione, senza il ritiro. |
price.freightCents | intero min 0, max 9007199254740991 | sì | Nolo prima del carburante. |
price.fuelCents | intero min 0, max 9007199254740991 | sì | Supplemento carburante. |
price.codFeeCents | intero min 0, max 9007199254740991 | sì | Costo del contrassegno. |
price.insuranceFeeCents | intero min 0, max 9007199254740991 | sì | Costo dell’assicurazione. |
price.servicesCents | intero min 0, max 9007199254740991 | sì | Servizi accessori. |
price.tailLiftCents | intero min 0, max 9007199254740991 | sì | Sponda idraulica. |
price.oversizeCents | intero min 0, max 9007199254740991 | sì | Colli ingombranti. |
price.services | array di oggetto | sì | |
price.services[].code | testo | sì | |
price.services[].label | testo | sì | |
price.services[].cents | intero min 0, max 9007199254740991 | sì | |
price.zone | "NATIONAL" | "SICILY" | "SARDINIA" | "MINOR_ISLANDS" | "INTERNATIONAL" | sì | |
price.zoneName | testo | sì | |
price.weight | oggetto | sì | |
price.weight.actualKg | numero min 0 | sì | Peso reale. |
price.weight.volumetricKg | numero min 0 | sì | Peso volumetrico (dalle misure). |
price.weight.chargeableKg | numero min 0 | sì | Peso su cui si calcola il prezzo. |
pickup | oggetto o null | sì | |
pickup.date | testo (date) | sì | |
pickup.state | "booking" | "booked" | "failed" | "cancelled" | sì | booking: da prenotare. booked: prenotato. failed: non riuscito, lo gestiamo noi. cancelled: annullato. |
pickup.carrierRef | qualunque | sì | Numero del ritiro presso il corriere, quando c’è. |
pickup.amountCents | intero min 0, max 9007199254740991 | sì | |
labelAvailable | sì/no | sì | L’etichetta si scarica con GET /v1/shipments/{id}/label. |
cancellation | "carrier" | "packhub" | "none" | sì | Come si annullerebbe adesso; none = non si può più annullare. |
failureReason | qualunque | sì | Con failed: perché il corriere l’ha rifiutata. |
events | array di oggetto | sì | Eventi del corriere, dal più recente. |
events[].at | testo (date-time) | sì | |
events[].status | qualunque | sì | Stato normalizzato, per esempio IN_TRANSITO, CONSEGNATO. |
events[].description | testo | sì | |
events[].location | qualunque | sì |
Risposte
200La stessa spedizione di una richiesta ripetuta.201Spedizione creata.400Richiesta non valida (VALIDATION_ERROR).401Chiave mancante, non valida o revocata (UNAUTHENTICATED).402Credito insufficiente (INSUFFICIENT_FUNDS).404Non trovato (NOT_FOUND).409Conflitto (IDEMPOTENCY_CONFLICT,CANCEL_NOT_ALLOWED).422Spedizione non possibile su questo contratto: il codice dice perché.429Troppe richieste (RATE_LIMITED): aspetta i secondi diRetry-After.503Corriere non raggiungibile (CARRIER_UNAVAILABLE).
/v1/shipmentsElenco delle spedizioni
Dalla più recente, a pagine: per la pagina dopo passa cursor con il nextCursor ricevuto. Una chiave di prova vede solo le spedizioni di prova.
Parametri
| Nome | Dove | Obbl. | Descrizione |
|---|---|---|---|
limit | nella query | ||
cursor | nella query | Il nextCursor della pagina prima. | |
status | nella query | creating: in verifica (il corriere non ha dato un esito: non ripetere). created: creata. failed: rifiutata dal corriere, nessun addebito. cancelled: annullata e rimborsata. | |
from | nella query | Create da questo giorno (ora italiana). | |
to | nella query | Create fino a questo giorno compreso (ora italiana). | |
trackingNumber | nella query | ||
reference | nella query |
curl -X GET "https://api.packhub.it/v1/shipments" \
-H "Authorization: Bearer $PACKHUB_KEY"const res = await fetch('https://api.packhub.it/v1/shipments', {
method: 'GET',
headers: {
Authorization: `Bearer ${process.env.PACKHUB_KEY}`,
},
});
const data = await res.json();
if (!res.ok) throw new Error(`${data.error.code}: ${data.error.message}`);
console.log(data);<?php
$ch = curl_init('https://api.packhub.it/v1/shipments');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('PACKHUB_KEY')],
]);
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$data = json_decode($response, true);
if ($status >= 400) {
throw new Exception($data['error']['code'] . ': ' . $data['error']['message']);
}
Campi della risposta
| Campo | Tipo | Obbl. | Descrizione |
|---|---|---|---|
items | array di oggetto | sì | |
items[].id | testo (uuid) | sì | Identificativo stabile della spedizione: il numero di tracking può cambiare. |
items[].mode | "live" | "test" | sì | test per le spedizioni di prova. |
items[].status | "creating" | "created" | "failed" | "cancelled" | sì | creating: in verifica (il corriere non ha dato un esito: non ripetere). created: creata. failed: rifiutata dal corriere, nessun addebito. cancelled: annullata e rimborsata. |
items[].createdAt | testo (date-time) | sì | |
items[].contractId | testo (uuid) | sì | |
items[].carrier | testo | sì | Corriere che consegna, per esempio BRT, GLS, POSTE, SDA. |
items[].contractName | testo | sì | |
items[].trackingNumber | qualunque | sì | Numero di tracking. Su alcuni contratti nasce con un riferimento provvisorio di PackHub (PK…) e poi diventa quello del corriere: GET /v1/tracking/{numero} accetta tutti e due. |
items[].trackingStatus | qualunque | sì | |
items[].reference | qualunque | sì | |
items[].recipient | oggetto | sì | |
items[].recipient.name | testo | sì | |
items[].recipient.city | testo | sì | |
items[].recipient.zipCode | testo | sì | |
items[].recipient.province | testo | sì | |
items[].parcelsCount | intero min 1, max 9007199254740991 | sì | |
items[].priceCents | intero min 0, max 9007199254740991 | sì | Quanto è stato addebitato per il trasporto. |
nextCursor | qualunque | sì | null = ultima pagina. |
Risposte
200Una pagina di spedizioni.400Richiesta non valida (VALIDATION_ERROR).401Chiave mancante, non valida o revocata (UNAUTHENTICATED).429Troppe richieste (RATE_LIMITED): aspetta i secondi diRetry-After.
/v1/shipments/{id}Dettaglio di una spedizione
Stato, tracking, prezzo pagato, ritiro ed eventi del corriere.
Parametri
| Nome | Dove | Obbl. | Descrizione |
|---|---|---|---|
id | nel percorso | sì | L’id della spedizione. |
curl -X GET "https://api.packhub.it/v1/shipments/<ID_SPEDIZIONE>" \
-H "Authorization: Bearer $PACKHUB_KEY"const res = await fetch('https://api.packhub.it/v1/shipments/<ID_SPEDIZIONE>', {
method: 'GET',
headers: {
Authorization: `Bearer ${process.env.PACKHUB_KEY}`,
},
});
const data = await res.json();
if (!res.ok) throw new Error(`${data.error.code}: ${data.error.message}`);
console.log(data);<?php
$ch = curl_init('https://api.packhub.it/v1/shipments/<ID_SPEDIZIONE>');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('PACKHUB_KEY')],
]);
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$data = json_decode($response, true);
if ($status >= 400) {
throw new Exception($data['error']['code'] . ': ' . $data['error']['message']);
}
Campi della risposta
| Campo | Tipo | Obbl. | Descrizione |
|---|---|---|---|
id | testo (uuid) | sì | Identificativo stabile della spedizione: il numero di tracking può cambiare. |
mode | "live" | "test" | sì | test per le spedizioni di prova. |
status | "creating" | "created" | "failed" | "cancelled" | sì | creating: in verifica (il corriere non ha dato un esito: non ripetere). created: creata. failed: rifiutata dal corriere, nessun addebito. cancelled: annullata e rimborsata. |
createdAt | testo (date-time) | sì | |
contractId | testo (uuid) | sì | |
carrier | testo | sì | Corriere che consegna, per esempio BRT, GLS, POSTE, SDA. |
contractName | testo | sì | |
trackingNumber | qualunque | sì | Numero di tracking. Su alcuni contratti nasce con un riferimento provvisorio di PackHub (PK…) e poi diventa quello del corriere: GET /v1/tracking/{numero} accetta tutti e due. |
trackingStatus | qualunque | sì | |
reference | qualunque | sì | |
recipient | oggetto | sì | |
recipient.name | testo | sì | |
recipient.contactName | testo | ||
recipient.street | testo | sì | |
recipient.houseNumber | testo | ||
recipient.city | testo | sì | |
recipient.zipCode | testo | sì | |
recipient.province | testo | ||
recipient.country | testo predefinito "IT" | sì | Codice ISO del paese, IT per l’Italia. |
recipient.territory | testo | ||
recipient.phone | testo | sì | |
recipient.email | testo | ||
recipient.notes | testo | ||
parcelsCount | intero min 1, max 9007199254740991 | sì | |
priceCents | intero min 0, max 9007199254740991 | sì | Quanto è stato addebitato per il trasporto. |
sender | oggetto | sì | |
sender.name | testo | sì | |
sender.contactName | testo | ||
sender.street | testo | sì | |
sender.houseNumber | testo | ||
sender.city | testo | sì | |
sender.zipCode | testo | sì | |
sender.province | testo | ||
sender.country | testo predefinito "IT" | sì | Codice ISO del paese, IT per l’Italia. |
sender.territory | testo | ||
sender.phone | testo | sì | |
sender.email | testo | ||
sender.notes | testo | ||
parcels | array di oggetto | sì | |
parcels[].weightKg | numero > 0, max 999.99 | sì | |
parcels[].lengthCm | numero > 0, max 999 | ||
parcels[].widthCm | numero > 0, max 999 | ||
parcels[].heightCm | numero > 0, max 999 | ||
codAmountCents | intero min 0, max 9007199254740991 | sì | |
insuranceAmountCents | intero min 0, max 9007199254740991 | sì | |
serviceParams | oggetto o null | sì | |
price | oggetto | sì | |
price.currency | "EUR" | sì | |
price.totalCents | intero min 0, max 9007199254740991 | sì | Totale della spedizione, senza il ritiro. |
price.freightCents | intero min 0, max 9007199254740991 | sì | Nolo prima del carburante. |
price.fuelCents | intero min 0, max 9007199254740991 | sì | Supplemento carburante. |
price.codFeeCents | intero min 0, max 9007199254740991 | sì | Costo del contrassegno. |
price.insuranceFeeCents | intero min 0, max 9007199254740991 | sì | Costo dell’assicurazione. |
price.servicesCents | intero min 0, max 9007199254740991 | sì | Servizi accessori. |
price.tailLiftCents | intero min 0, max 9007199254740991 | sì | Sponda idraulica. |
price.oversizeCents | intero min 0, max 9007199254740991 | sì | Colli ingombranti. |
price.services | array di oggetto | sì | |
price.services[].code | testo | sì | |
price.services[].label | testo | sì | |
price.services[].cents | intero min 0, max 9007199254740991 | sì | |
price.zone | "NATIONAL" | "SICILY" | "SARDINIA" | "MINOR_ISLANDS" | "INTERNATIONAL" | sì | |
price.zoneName | testo | sì | |
price.weight | oggetto | sì | |
price.weight.actualKg | numero min 0 | sì | Peso reale. |
price.weight.volumetricKg | numero min 0 | sì | Peso volumetrico (dalle misure). |
price.weight.chargeableKg | numero min 0 | sì | Peso su cui si calcola il prezzo. |
pickup | oggetto o null | sì | |
pickup.date | testo (date) | sì | |
pickup.state | "booking" | "booked" | "failed" | "cancelled" | sì | booking: da prenotare. booked: prenotato. failed: non riuscito, lo gestiamo noi. cancelled: annullato. |
pickup.carrierRef | qualunque | sì | Numero del ritiro presso il corriere, quando c’è. |
pickup.amountCents | intero min 0, max 9007199254740991 | sì | |
labelAvailable | sì/no | sì | L’etichetta si scarica con GET /v1/shipments/{id}/label. |
cancellation | "carrier" | "packhub" | "none" | sì | Come si annullerebbe adesso; none = non si può più annullare. |
failureReason | qualunque | sì | Con failed: perché il corriere l’ha rifiutata. |
events | array di oggetto | sì | Eventi del corriere, dal più recente. |
events[].at | testo (date-time) | sì | |
events[].status | qualunque | sì | Stato normalizzato, per esempio IN_TRANSITO, CONSEGNATO. |
events[].description | testo | sì | |
events[].location | qualunque | sì |
Risposte
200La spedizione.401Chiave mancante, non valida o revocata (UNAUTHENTICATED).404Non trovato (NOT_FOUND).429Troppe richieste (RATE_LIMITED): aspetta i secondi diRetry-After.
/v1/shipments/{id}/labelScarica l’etichetta
Il PDF dell’etichetta, da salvare così com’è. Dopo l’annullamento non si scarica più. Se il corriere non l’ha ancora pronta risponde 503: riprova tra poco.
Parametri
| Nome | Dove | Obbl. | Descrizione |
|---|---|---|---|
id | nel percorso | sì | L’id della spedizione. |
curl -X GET "https://api.packhub.it/v1/shipments/<ID_SPEDIZIONE>/label" \
-H "Authorization: Bearer $PACKHUB_KEY" \
-o etichetta.pdfconst res = await fetch('https://api.packhub.it/v1/shipments/<ID_SPEDIZIONE>/label', {
method: 'GET',
headers: {
Authorization: `Bearer ${process.env.PACKHUB_KEY}`,
},
});
const pdf = Buffer.from(await res.arrayBuffer());
await fs.promises.writeFile('etichetta.pdf', pdf);<?php
$ch = curl_init('https://api.packhub.it/v1/shipments/<ID_SPEDIZIONE>/label');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('PACKHUB_KEY')],
]);
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
file_put_contents('etichetta.pdf', $response);
Risposte
200L’etichetta.401Chiave mancante, non valida o revocata (UNAUTHENTICATED).404Non trovato (NOT_FOUND).429Troppe richieste (RATE_LIMITED): aspetta i secondi diRetry-After.503Corriere non raggiungibile (CARRIER_UNAVAILABLE).
/v1/shipments/{id}/cancelAnnulla una spedizione
Annulla e rimborsa sul wallet. Con cancellation: carrier l’annullamento arriva al corriere e il rimborso parte solo se il corriere conferma. Con packhub il corriere non ha l’annullamento automatico: la spedizione si annulla in PackHub, e se il pacco viene consegnato lo stesso si riaddebita. Dopo la presa in carico non si annulla più. Ripetere su una spedizione annullata dà la stessa risposta.
Parametri
| Nome | Dove | Obbl. | Descrizione |
|---|---|---|---|
id | nel percorso | sì | L’id della spedizione. |
curl -X POST "https://api.packhub.it/v1/shipments/<ID_SPEDIZIONE>/cancel" \
-H "Authorization: Bearer $PACKHUB_KEY"const res = await fetch('https://api.packhub.it/v1/shipments/<ID_SPEDIZIONE>/cancel', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.PACKHUB_KEY}`,
},
});
const data = await res.json();
if (!res.ok) throw new Error(`${data.error.code}: ${data.error.message}`);
console.log(data);<?php
$ch = curl_init('https://api.packhub.it/v1/shipments/<ID_SPEDIZIONE>/cancel');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('PACKHUB_KEY')],
]);
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$data = json_decode($response, true);
if ($status >= 400) {
throw new Exception($data['error']['code'] . ': ' . $data['error']['message']);
}
Campi della risposta
| Campo | Tipo | Obbl. | Descrizione |
|---|---|---|---|
id | testo (uuid) | sì | Identificativo stabile della spedizione: il numero di tracking può cambiare. |
mode | "live" | "test" | sì | test per le spedizioni di prova. |
status | "creating" | "created" | "failed" | "cancelled" | sì | creating: in verifica (il corriere non ha dato un esito: non ripetere). created: creata. failed: rifiutata dal corriere, nessun addebito. cancelled: annullata e rimborsata. |
createdAt | testo (date-time) | sì | |
contractId | testo (uuid) | sì | |
carrier | testo | sì | Corriere che consegna, per esempio BRT, GLS, POSTE, SDA. |
contractName | testo | sì | |
trackingNumber | qualunque | sì | Numero di tracking. Su alcuni contratti nasce con un riferimento provvisorio di PackHub (PK…) e poi diventa quello del corriere: GET /v1/tracking/{numero} accetta tutti e due. |
trackingStatus | qualunque | sì | |
reference | qualunque | sì | |
recipient | oggetto | sì | |
recipient.name | testo | sì | |
recipient.contactName | testo | ||
recipient.street | testo | sì | |
recipient.houseNumber | testo | ||
recipient.city | testo | sì | |
recipient.zipCode | testo | sì | |
recipient.province | testo | ||
recipient.country | testo predefinito "IT" | sì | Codice ISO del paese, IT per l’Italia. |
recipient.territory | testo | ||
recipient.phone | testo | sì | |
recipient.email | testo | ||
recipient.notes | testo | ||
parcelsCount | intero min 1, max 9007199254740991 | sì | |
priceCents | intero min 0, max 9007199254740991 | sì | Quanto è stato addebitato per il trasporto. |
sender | oggetto | sì | |
sender.name | testo | sì | |
sender.contactName | testo | ||
sender.street | testo | sì | |
sender.houseNumber | testo | ||
sender.city | testo | sì | |
sender.zipCode | testo | sì | |
sender.province | testo | ||
sender.country | testo predefinito "IT" | sì | Codice ISO del paese, IT per l’Italia. |
sender.territory | testo | ||
sender.phone | testo | sì | |
sender.email | testo | ||
sender.notes | testo | ||
parcels | array di oggetto | sì | |
parcels[].weightKg | numero > 0, max 999.99 | sì | |
parcels[].lengthCm | numero > 0, max 999 | ||
parcels[].widthCm | numero > 0, max 999 | ||
parcels[].heightCm | numero > 0, max 999 | ||
codAmountCents | intero min 0, max 9007199254740991 | sì | |
insuranceAmountCents | intero min 0, max 9007199254740991 | sì | |
serviceParams | oggetto o null | sì | |
price | oggetto | sì | |
price.currency | "EUR" | sì | |
price.totalCents | intero min 0, max 9007199254740991 | sì | Totale della spedizione, senza il ritiro. |
price.freightCents | intero min 0, max 9007199254740991 | sì | Nolo prima del carburante. |
price.fuelCents | intero min 0, max 9007199254740991 | sì | Supplemento carburante. |
price.codFeeCents | intero min 0, max 9007199254740991 | sì | Costo del contrassegno. |
price.insuranceFeeCents | intero min 0, max 9007199254740991 | sì | Costo dell’assicurazione. |
price.servicesCents | intero min 0, max 9007199254740991 | sì | Servizi accessori. |
price.tailLiftCents | intero min 0, max 9007199254740991 | sì | Sponda idraulica. |
price.oversizeCents | intero min 0, max 9007199254740991 | sì | Colli ingombranti. |
price.services | array di oggetto | sì | |
price.services[].code | testo | sì | |
price.services[].label | testo | sì | |
price.services[].cents | intero min 0, max 9007199254740991 | sì | |
price.zone | "NATIONAL" | "SICILY" | "SARDINIA" | "MINOR_ISLANDS" | "INTERNATIONAL" | sì | |
price.zoneName | testo | sì | |
price.weight | oggetto | sì | |
price.weight.actualKg | numero min 0 | sì | Peso reale. |
price.weight.volumetricKg | numero min 0 | sì | Peso volumetrico (dalle misure). |
price.weight.chargeableKg | numero min 0 | sì | Peso su cui si calcola il prezzo. |
pickup | oggetto o null | sì | |
pickup.date | testo (date) | sì | |
pickup.state | "booking" | "booked" | "failed" | "cancelled" | sì | booking: da prenotare. booked: prenotato. failed: non riuscito, lo gestiamo noi. cancelled: annullato. |
pickup.carrierRef | qualunque | sì | Numero del ritiro presso il corriere, quando c’è. |
pickup.amountCents | intero min 0, max 9007199254740991 | sì | |
labelAvailable | sì/no | sì | L’etichetta si scarica con GET /v1/shipments/{id}/label. |
cancellation | "carrier" | "packhub" | "none" | sì | Come si annullerebbe adesso; none = non si può più annullare. |
failureReason | qualunque | sì | Con failed: perché il corriere l’ha rifiutata. |
events | array di oggetto | sì | Eventi del corriere, dal più recente. |
events[].at | testo (date-time) | sì | |
events[].status | qualunque | sì | Stato normalizzato, per esempio IN_TRANSITO, CONSEGNATO. |
events[].description | testo | sì | |
events[].location | qualunque | sì |
Risposte
200La spedizione annullata.401Chiave mancante, non valida o revocata (UNAUTHENTICATED).404Non trovato (NOT_FOUND).409Conflitto (IDEMPOTENCY_CONFLICT,CANCEL_NOT_ALLOWED).429Troppe richieste (RATE_LIMITED): aspetta i secondi diRetry-After.503Corriere non raggiungibile (CARRIER_UNAVAILABLE).
Tracking
/v1/tracking/{number}Tracking da numero
Gli eventi del corriere di una tua spedizione, dal numero di tracking. Accetta anche il riferimento provvisorio PK… che alcune spedizioni hanno prima del numero del corriere.
Parametri
| Nome | Dove | Obbl. | Descrizione |
|---|---|---|---|
number | nel percorso | sì | Il numero di tracking. |
curl -X GET "https://api.packhub.it/v1/tracking/<NUMERO_TRACKING>" \
-H "Authorization: Bearer $PACKHUB_KEY"const res = await fetch('https://api.packhub.it/v1/tracking/<NUMERO_TRACKING>', {
method: 'GET',
headers: {
Authorization: `Bearer ${process.env.PACKHUB_KEY}`,
},
});
const data = await res.json();
if (!res.ok) throw new Error(`${data.error.code}: ${data.error.message}`);
console.log(data);<?php
$ch = curl_init('https://api.packhub.it/v1/tracking/<NUMERO_TRACKING>');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('PACKHUB_KEY')],
]);
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$data = json_decode($response, true);
if ($status >= 400) {
throw new Exception($data['error']['code'] . ': ' . $data['error']['message']);
}
Campi della risposta
| Campo | Tipo | Obbl. | Descrizione |
|---|---|---|---|
shipmentId | testo (uuid) | sì | |
mode | "live" | "test" | sì | |
trackingNumber | qualunque | sì | Il numero attuale. |
carrier | testo | sì | Corriere che consegna, per esempio BRT, GLS, POSTE, SDA. |
status | "creating" | "created" | "failed" | "cancelled" | sì | creating: in verifica (il corriere non ha dato un esito: non ripetere). created: creata. failed: rifiutata dal corriere, nessun addebito. cancelled: annullata e rimborsata. |
trackingStatus | qualunque | sì | |
events | array di oggetto | sì | |
events[].at | testo (date-time) | sì | |
events[].status | qualunque | sì | Stato normalizzato, per esempio IN_TRANSITO, CONSEGNATO. |
events[].description | testo | sì | |
events[].location | qualunque | sì |
Risposte
200Il tracking.401Chiave mancante, non valida o revocata (UNAUTHENTICATED).404Non trovato (NOT_FOUND).429Troppe richieste (RATE_LIMITED): aspetta i secondi diRetry-After.