> For the complete documentation index, see [llms.txt](https://apidocs.gsped.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://apidocs.gsped.com/gsped-api-english-version/spedizioni-e-dintorni/shipment.md).

# Shipment

Shipment management

## Shipment - GET

This endpoint lets you manage the creation, retrieval and deletion of shipments on Gsped.

## Shipment -GET

<mark style="color:blue;">`GET`</mark> `https://api.gsped.it/[INSTANCE]/Shipment`

Retrieves all the information of a shipment, including the labels

#### Query Parameters

| Name                                 | Type   | Description                     |
| ------------------------------------ | ------ | ------------------------------- |
| id<mark style="color:red;">\*</mark> | String | Unique Gsped ID of the shipment |

#### Headers

| Name                                        | Type   | Description              |
| ------------------------------------------- | ------ | ------------------------ |
| x-api-key<mark style="color:red;">\*</mark> | String | Apikey provided by GSPED |

{% tabs %}
{% tab title="200: OK Shipment information" %}

```javascript
{
    // Response
}
```

{% endtab %}

{% tab title="400: Bad Request Input error" %}

```javascript
{
    // Response
}
```

{% endtab %}

{% tab title="403: Forbidden Invalid apikey" %}

```javascript
{
    // Response
}
```

{% endtab %}

{% tab title="404: Not Found Shipment not found" %}

```javascript
{
    // Response
}
```

{% endtab %}
{% endtabs %}

### Example code snippets

{% tabs %}
{% tab title="PHP" %}

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.gsped.it/sandbox/Shipment?id=70059765",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_POSTFIELDS => "",
  CURLOPT_HTTPHEADER => [
    "x-api-key: YOUR-API-KEY"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
```

{% endtab %}

{% tab title="PYTHON" %}

```python
import http.client

conn = http.client.HTTPSConnection("api.gsped.it")

payload = ""

headers = { 'x-api-key': "YOUR-API-KEY" }

conn.request("GET", "/sandbox/Shipment?id=70059765", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
```

{% endtab %}

{% tab title="GO" %}

```go
package main

import (
	"fmt"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://api.gsped.it/sandbox/Shipment?id=70059765"

	req, _ := http.NewRequest("GET", url, nil)

	req.Header.Add("x-api-key", "YOUR-API-KEY")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

{% endtab %}

{% tab title="C#" %}

```csharp
var client = new HttpClient();
var request = new HttpRequestMessage
{
    Method = HttpMethod.Get,
    RequestUri = new Uri("https://api.gsped.it/sandbox/Shipment?id=70059765"),
    Headers =
    {
        { "x-api-key", "YOUR-API-KEY" },
    },
};
using (var response = await client.SendAsync(request))
{
    response.EnsureSuccessStatusCode();
    var body = await response.Content.ReadAsStringAsync();
    Console.WriteLine(body);
}
```

{% endtab %}

{% tab title="cURL" %}

```shell
curl --request GET \
  --url 'https://api.gsped.it/sandbox/Shipment?id=70059765' \
  --header 'x-api-key: YOUR-API-KEY'
```

{% endtab %}
{% endtabs %}

## Shipment - POST

The Shipment POST call lets you create the shipment.

If the operation is successful, it returns the shipment data together with its labels in the available formats.

{% hint style="info" %}
Creating a shipment does not always succeed: both Gsped and the courier's systems run a series of checks on the correctness of the data received, so make sure you handle possible errors correctly!
{% endhint %}

{% hint style="warning" %}
**PLEASE NOTE**\
Each courier has limits on the length of individual fields.\
Check the allowed length on the page of the individual courier (if available); otherwise our technicians can tell you the lengths for the couriers you use.
{% endhint %}

The logic to implement to check the outcome of the calls is as follows:

in the API response to the shipment creation POST, first check the HTTP response code: if it is 400, the data sent did not pass the first series of data checks, and in that case the error field contains details of the problem found (for example missing required fields).

If the response code is 200, the data passed the first level of validation and generation of the waybill has started. You then need to check the value of the status field: if it contains 0, the waybill was generated correctly and can be retrieved from the dedicated fields in the response. **If instead the status field is equal to 0.6, waybill generation failed and the error field contains the description of the error.** This type of error can occur in situations such as inconsistent postcode and town, an address not accepted by the courier's systems, a requested service not available for the destination town, *et cetera*.

{% hint style="info" %}
The following fields proposed in the example belong to a set that can be considered "basic" and common to more or less all couriers for creating shipments.\
If you want to extend the functionality or need to request features available with a specific courier, see the [Shipment objects](https://apidocs.gsped.com/gsped-api-english-version/spedizioni-e-dintorni/shipment/shipment-objects), [use cases](https://apidocs.gsped.com/gsped-api-english-version/spedizioni-e-dintorni/shipment/casi-duso) or [couriers](https://apidocs.gsped.com/gsped-api-english-version/spedizioni-e-dintorni/shipment/corrieri) sections.
{% endhint %}

## Shipment POST

<mark style="color:green;">`POST`</mark> `https://api.gsped.it/[INSTANCE]/Shipment`

Create a shipment

#### Headers

| Name                                        | Type   | Description              |
| ------------------------------------------- | ------ | ------------------------ |
| x-api-key<mark style="color:red;">\*</mark> | String | Apikey provided by Gsped |

#### Request Body

| Name                                                  | Type   | Description                                                                                                                                                                                                                                                |
| ----------------------------------------------------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| corriere<mark style="color:red;">\*</mark>            | Int    | Gsped courier ID ( [Couriers and services](/gsped-api-english-version/overview/corrieri-e-servizi.md) )                                                                                                                                                    |
| colli<mark style="color:red;">\*</mark>               | Int    | Number of parcels in the shipment                                                                                                                                                                                                                          |
| volume<mark style="color:red;">\*</mark>              | Float  | Shipment volume in cubic metres                                                                                                                                                                                                                            |
| peso<mark style="color:red;">\*</mark>                | Float  | Shipment weight in KG                                                                                                                                                                                                                                      |
| origine<mark style="color:red;">\*</mark>             | String | Country of origin of the goods, 2-char ISO code                                                                                                                                                                                                            |
| merce<mark style="color:red;">\*</mark>               | String | Generic description of the goods shipped                                                                                                                                                                                                                   |
| ddt\_num                                              | String | Numeric reference of the shipment; if not set, Gsped creates one automatically                                                                                                                                                                             |
| ddt\_alpha                                            | String | Alphanumeric reference of the shipment; if not set, Gsped creates one automatically                                                                                                                                                                        |
| client\_id<mark style="color:red;">\*</mark>          | Int    | Client ID provided by Gsped                                                                                                                                                                                                                                |
| servizio<mark style="color:red;">\*</mark>            | Int    | Gsped service ID ( [Couriers and services](/gsped-api-english-version/overview/corrieri-e-servizi.md) )                                                                                                                                                    |
| sender\_cap                                           | String | Sender zipcode                                                                                                                                                                                                                                             |
| sender\_city                                          | String | Sender town/city                                                                                                                                                                                                                                           |
| sender\_addr                                          | String | Sender address                                                                                                                                                                                                                                             |
| sender\_contact                                       | String | Sender contact name                                                                                                                                                                                                                                        |
| sender\_name                                          | String | Sender name                                                                                                                                                                                                                                                |
| rcpt\_contact<mark style="color:red;">\*</mark>       | String | Recipient contact name                                                                                                                                                                                                                                     |
| rcpt\_name<mark style="color:red;">\*</mark>          | String | Recipient name                                                                                                                                                                                                                                             |
| sender\_email                                         | String | Sender email                                                                                                                                                                                                                                               |
| sender\_phone                                         | String | Sender phone                                                                                                                                                                                                                                               |
| sender\_country\_code                                 | String | Sender country, 2-char ISO code                                                                                                                                                                                                                            |
| rcpt\_prov<mark style="color:red;">\*</mark>          | String | Recipient province/state, 2-char ISO code                                                                                                                                                                                                                  |
| rcpt\_cap<mark style="color:red;">\*</mark>           | String | Recipient zipcode                                                                                                                                                                                                                                          |
| rcpt\_city<mark style="color:red;">\*</mark>          | String | Recipient town/city                                                                                                                                                                                                                                        |
| rcpt\_addr<mark style="color:red;">\*</mark>          | String | Recipient address                                                                                                                                                                                                                                          |
| sender\_prov                                          | String | Sender province/state, 2-char ISO code                                                                                                                                                                                                                     |
| rcpt\_phone<mark style="color:red;">\*</mark>         | String | Recipient phone                                                                                                                                                                                                                                            |
| rcpt\_email<mark style="color:red;">\*</mark>         | String | Recipient email                                                                                                                                                                                                                                            |
| rcpt\_emails\_extra                                   | Array  | Additional emails for other recipients                                                                                                                                                                                                                     |
| rcpt\_country\_code<mark style="color:red;">\*</mark> | String | Recipient country, 2-char ISO code                                                                                                                                                                                                                         |
| note\_sender                                          | String | Sender notes                                                                                                                                                                                                                                               |
| valuta                                                |        | ISO 4217 currency code                                                                                                                                                                                                                                     |
| valore                                                | Float  | Insured amount                                                                                                                                                                                                                                             |
| dropshipping                                          | String | Flag 1 to send the waybill to the sender's email                                                                                                                                                                                                           |
| al\_sabato                                            | String | Flag S\|N to enable the Saturday service (enabled couriers only)                                                                                                                                                                                           |
| al\_piano                                             | String | Flag S\|N to enable the floor delivery service (enabled couriers only)                                                                                                                                                                                     |
| preavviso\_telefonico                                 | String | Flag S\|N to enable the service (enabled couriers only)                                                                                                                                                                                                    |
| fermo\_deposito                                       | String | Flag S\|N to identify a hold at depot shipment                                                                                                                                                                                                             |
| reso\_contestuale                                     | String | Flag S\|N to enable the EXCHANGE service (enabled couriers only)                                                                                                                                                                                           |
| documenti                                             | String | Flag 0\|1 to identify a documents shipment                                                                                                                                                                                                                 |
| flag\_reso                                            | Int    | Flag 0\|1 to identify a return shipment                                                                                                                                                                                                                    |
| addebito\_dogana                                      | Int    | <p>Assignment of customs duties.<br>Allowed values:<br>- <strong>0 :</strong> Customs duties charged to the recipient<br>- <strong>1 :</strong> Customs duties charged to the sender<br>- <strong>2 :</strong> Customs duties charged to a third party</p> |
| chi\_paga                                             | Int    | <p>Assignment of shipping costs:<br>- <strong>0 :</strong> The sender pays<br>- <strong>1 :</strong> The recipient pays</p>                                                                                                                                |
| valore\_doganale                                      | Float  | Customs value                                                                                                                                                                                                                                              |
| id\_order\_gelproximity                               | String | Order ID on the Gel Proximity systems for sending tracking                                                                                                                                                                                                 |
| invoice\_date                                         | String | Invoice date in YYYY-MM-GG format                                                                                                                                                                                                                          |
| invoice\_number                                       | String | Invoice number                                                                                                                                                                                                                                             |
| invoiced\_client\_id                                  | Int    | <p>TO BE SET ONLY FOR RESELLER INSTANCES<br>Use it to specify which of the reseller's clients the shipment should be associated with.</p>                                                                                                                  |
| labelType                                             | Enum   | <p>Optional field to define the requested label type.<br><br>Possible values: PDF/ZPL<br><br>Warning: some couriers may have format limitations</p>                                                                                                        |

{% tabs %}
{% tab title="200: OK Shipment created" %}

```javascript
{
  "client_id": 390,
  "cod_destinatario": "",
  "colli": 1,
  "contrassegno": 0,
  "corriere": 104,
  "date_req_cons": "0000-00-00 00:00:00",
  "ddt_alpha": "TEST_GSPED",
  "ddt_num": 12346,
  "merce": "",
  "note_sender": "",
  "origine": "IT",
  "peso": 1.8,
  "preavviso_telefonico": "",
  "rcpt_addr": "115 E Endfield Rd",
  "rcpt_cap": 19053,
  "rcpt_city": "Feasterville Trevose",
  "rcpt_contact": "Tester",
  "rcpt_country_code": "US",
  "rcpt_email": "test@test.edu",
  "rcpt_emails_extra": ["mail1@example.com", "mail2@example.com"],
  "rcpt_name": "TEST MITTENTE",
  "rcpt_phone": "123456789",
  "rcpt_prov": "PA",
  "servizio": 9,
  "tipo_incasso": 0,
  "valore": 0,
  "valore_doganale": 37.5,
  "volume": 0.029,
  "status": 0,
  "fid_partenza": "",
  "num_serie": 0,
  "num_spedizione": "1253863656",
  "date_upd": "0000-00-00 00:00:00",
  "error": "",
  "sender_name": "test mittente",
  "sender_addr": "p.za Ambrosoli 13",
  "sender_cap": 15121,
  "sender_city": "Alessandria",
  "sender_contact": "Rossi Pino",
  "sender_prov": "AL",
  "sender_country_code": "IT",
  "sender_email": "test@test.it",
  "label_jpg": [
    "base64 encoded label string"
  ],
  "label_pdf": [
    "base64 encoded label string"
  ],
  "label_zpl": [
    "ZPL label string"
  ],
  "id": 50003621,
  "tnt_options": [],
  "tracking_link": "",
  "valuta": "EUR",
  "dropshipping": 0,
  "sender_phone": 12345562,
  "al_piano": "",
  "al_sabato": "",
  "reso_contestuale": "",
  "fermo_deposito": 0,
  "note": "",
  "centro_costo": "",
  "sda_servizio": "",
  "user_id": 0,
  "opening_time": "00:00:00",
  "closing_time": "00:00:00",
  "date_req_ritiro": "0000-00-00 00:00:00",
  "ups_uap_id": "",
  "sda_id_fermoposta": "",
  "note_2": "",
  "confermato": 0,
  "ups_signature_required": 0,
  "id_pickup": null,
  "documenti": 0,
  "sda_accessori": 0,
  "packaging": "",
  "dropoff_type": "",
  "vat_seller": "",
  "vat_buyer": "",
  "generic_service_point": "",
  "tipo_transazione": "supSoglia",
  "rcpt_language": "",
  "sender_eori": "",
  "rcpt_eori": "",
  "link_pickup_booking": ""
}
```

{% endtab %}

{% tab title="400: Bad Request Wrong input" %}

```javascript
{
  "error": "client_id: deve essere lungo al massimo 7 caratteri"
}
```

{% endtab %}

{% tab title="403: Forbidden Invalid apikey" %}

```javascript
{
  "status": false,
  "error": "Invalid API key "
}
```

{% endtab %}
{% endtabs %}

### Example code snippets

{% tabs %}
{% tab title="PHP" %}

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.gsped.it/sandbox/shipment",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "{\n  \"client_id\": 390,\n  \"colli\": 2,\n  \"corriere\": 104,\n  \"ddt_alpha\": \"TEST_GSPED\",\n  \"ddt_num\": 12346,\n  \"origine\": \"IT\",\n\t\"dropshipping\" : 0,\n  \"peso\": 2.4,\n  \"rcpt_addr\": \"115 E Endfield Rd\",\n  \"rcpt_cap\": \"19053\",\n  \"rcpt_city\": \"Feasterville Trevose\",\n  \"rcpt_contact\": \"Tester\",\n  \"rcpt_country_code\": \"US\",\n  \"rcpt_email\": \"test@test.it\",\n  \"rcpt_name\": \"TEST DESTINATARIO\",\n  \"rcpt_phone\": \"2159005458\",\n  \"rcpt_prov\": \"PA\",\n  \"servizio\": 9,\n  \"valore\": 0,\n  \"valore_doganale\": 37.50,\n  \"valuta\": \"EUR\",\n  \"volume\": 0.0972,\n  \"invoiced_client_id\": 1001}",
  CURLOPT_HTTPHEADER => [
    "x-api-key: YOUR-API-KEY"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
```

{% endtab %}

{% tab title="PYTHON" %}

```python
import http.client
import json

conn = http.client.HTTPSConnection("api.gsped.it")

payload = json.dumps({
  "client_id": 390,
  "colli": 2,
  "corriere": 104,
  "ddt_alpha": "TEST_GSPED",
  "ddt_num": 12346,
  "origine": "IT",
  "dropshipping": 0,
  "peso": 2.4,
  "rcpt_addr": "115 E Endfield Rd",
  "rcpt_cap": "19053",
  "rcpt_city": "Feasterville Trevose",
  "rcpt_contact": "Tester",
  "rcpt_country_code": "US",
  "rcpt_email": "test@test.it",
  "rcpt_name": "TEST DESTINATARIO",
  "rcpt_phone": "2159005458",
  "rcpt_prov": "PA",
  "servizio": 9,
  "valore": 0,
  "valore_doganale": 37.50,
  "valuta": "EUR",
  "volume": 0.0972,
  "invoiced_client_id": 1001
})

headers = { 'x-api-key': "YOUR-API-KEY" }

conn.request("POST", "/sandbox/shipment", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
```

{% endtab %}

{% tab title="GO" %}

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://api.gsped.it/sandbox/shipment"

	payload := strings.NewReader("{\n  \"client_id\": 390,\n  \"colli\": 2,\n  \"corriere\": 104,\n  \"ddt_alpha\": \"TEST_GSPED\",\n  \"ddt_num\": 12346,\n  \"origine\": \"IT\",\n\t\"dropshipping\" : 0,\n  \"peso\": 2.4,\n  \"rcpt_addr\": \"115 E Endfield Rd\",\n  \"rcpt_cap\": \"19053\",\n  \"rcpt_city\": \"Feasterville Trevose\",\n  \"rcpt_contact\": \"Tester\",\n  \"rcpt_country_code\": \"US\",\n  \"rcpt_email\": \"test@test.it\",\n  \"rcpt_name\": \"TEST DESTINATARIO\",\n  \"rcpt_phone\": \"2159005458\",\n  \"rcpt_prov\": \"PA\",\n  \"servizio\": 9,\n  \"valore\": 0,\n  \"valore_doganale\": 37.50,\n  \"valuta\": \"EUR\",\n  \"volume\": 0.0972,\n  \"invoiced_client_id\": 1001}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("x-api-key", "YOUR-API-KEY")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

{% endtab %}

{% tab title="C#" %}

```csharp
var client = new HttpClient();
var request = new HttpRequestMessage
{
    Method = HttpMethod.Post,
    RequestUri = new Uri("https://api.gsped.it/sandbox/shipment"),
    Headers =
    {
        { "x-api-key", "YOUR-API-KEY" },
    },
    Content = new StringContent("{\n  \"client_id\": 390,\n  \"colli\": 2,\n  \"corriere\": 104,\n  \"ddt_alpha\": \"TEST_GSPED\",\n  \"ddt_num\": 12346,\n  \"origine\": \"IT\",\n\t\"dropshipping\" : 0,\n  \"peso\": 2.4,\n  \"rcpt_addr\": \"115 E Endfield Rd\",\n  \"rcpt_cap\": \"19053\",\n  \"rcpt_city\": \"Feasterville Trevose\",\n  \"rcpt_contact\": \"Tester\",\n  \"rcpt_country_code\": \"US\",\n  \"rcpt_email\": \"test@test.it\",\n  \"rcpt_name\": \"TEST DESTINATARIO\",\n  \"rcpt_phone\": \"2159005458\",\n  \"rcpt_prov\": \"PA\",\n  \"servizio\": 9,\n  \"valore\": 0,\n  \"valore_doganale\": 37.50,\n  \"valuta\": \"EUR\",\n  \"volume\": 0.0972,\n  \"invoiced_client_id\": 1001}")
    {
        Headers =
        {
            ContentType = new MediaTypeHeaderValue("application/json")
        }
    }
};
using (var response = await client.SendAsync(request))
{
    response.EnsureSuccessStatusCode();
    var body = await response.Content.ReadAsStringAsync();
    Console.WriteLine(body);
}
```

{% endtab %}

{% tab title="cURL" %}

```shell
curl --request POST \
  --url https://api.gsped.it/sandbox/shipment \
  --header 'x-api-key: YOUR-API-KEY' \
  --data '{
  "client_id": 390,
  "colli": 2,
  "corriere": 104,
  "ddt_alpha": "TEST_GSPED",
  "ddt_num": 12346,
  "origine": "IT",
  "dropshipping" : 0,
  "peso": 2.4,
  "rcpt_addr": "115 E Endfield Rd",
  "rcpt_cap": "19053",
  "rcpt_city": "Feasterville Trevose",
  "rcpt_contact": "Tester",
  "rcpt_country_code": "US",
  "rcpt_email": "test@test.it",
  "rcpt_name": "TEST DESTINATARIO",
  "rcpt_phone": "2159005458",
  "rcpt_prov": "PA",
  "servizio": 9,
  "valore": 0,
  "valore_doganale": 37.50,
  "valuta": "EUR",
  "volume": 0.0972,
  "invoiced_client_id": 1001
}'
```

{% endtab %}
{% endtabs %}

### Choosing the cheapest courier

If you want Gsped to choose the cheapest courier based on your price lists (configured on Gsped), set **corriere = 0** and **servizio = 0** in the call

**Payload example:**

```
{
    "client_id": 391,
    "corriere": 0,
    "servizio": 0,
    "ddt_num": 123,
    "ddt_alpha": "Test123",
    "colli": 1,
    "rcpt_name": "Test destinatario",
    "rcpt_addr": "INDUSTRIESTRASSE 7",
    "rcpt_cap": "4313",
    "rcpt_city": "MOEHLIN",
    "rcpt_country_code": "CH",
    "rcpt_email": "test@gsped.com",
    "sender_name": "Test mittente",
    "sender_addr": "Via Marzorati 14",
    "sender_cap": "20014",
    "sender_city": "Nerviano",
    "sender_country_code": "IT",
    "peso": 1,
    "volume": 0
}
```

## Shipment - DELETE

This endpoint lets you delete previously created shipments **only if they have not yet been confirmed.**

{% hint style="info" %}
When you delete a shipment, the labels returned by the POST are NO longer valid and must be discarded!
{% endhint %}

## Shipment DELETE

<mark style="color:red;">`DELETE`</mark> `https://api.gsped.it/[INSTANCE]/Shipment`

Deletion of a shipment on the Gsped and courier systems

#### Query Parameters

| Name                                 | Type   | Description                     |
| ------------------------------------ | ------ | ------------------------------- |
| id<mark style="color:red;">\*</mark> | String | Unique Gsped ID of the shipment |

#### Headers

| Name                                        | Type   | Description              |
| ------------------------------------------- | ------ | ------------------------ |
| x-api-key<mark style="color:red;">\*</mark> | String | Apikey provided by Gsped |

{% tabs %}
{% tab title="200: OK Deletion completed" %}

```javascript
{
  "error": ""
}
```

{% endtab %}

{% tab title="404: Not Found Shipment not found" %}

```javascript
{
  "error": "Spedizione non trovata"
}
```

{% endtab %}

{% tab title="403: Forbidden Invalid apikey" %}

```javascript
{
  "status": false,
  "error": "Invalid API key "
}
```

{% endtab %}

{% tab title="400: Bad Request Input error" %}

```javascript
{
  "error": "ID spedizione non indicata"
}
```

{% endtab %}

{% tab title="405: Method Not Allowed Shipment already confirmed" %}

```javascript
{
  "error": "Impossibile cancellare spedizione confermata"
}
```

{% endtab %}
{% endtabs %}

### Example code snippets

{% tabs %}
{% tab title="PHP" %}

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "http://api.gsped.it/sandbox/Shipment?id=53",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "DELETE",
  CURLOPT_POSTFIELDS => "",
  CURLOPT_HTTPHEADER => [
    "x-api-key: YOUR-API-KEY"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
```

{% endtab %}

{% tab title="PYTHON" %}

```python
import http.client

conn = http.client.HTTPConnection("api.gsped.it")

payload = ""

headers = {
    'x-api-key': "YOUR-API-KEY"
    }

conn.request("DELETE", "/sandbox/Shipment?id=53", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
```

{% endtab %}

{% tab title="GO" %}

```go
package main

import (
	"fmt"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "http://api.gsped.it/sandbox/Shipment?id=53"

	req, _ := http.NewRequest("DELETE", url, nil)
	
	req.Header.Add("x-api-key", "YOUR-API-KEY")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

{% endtab %}

{% tab title="C#" %}

```csharp
var clientHandler = new HttpClientHandler
{
    UseCookies = false,
};
var client = new HttpClient(clientHandler);
var request = new HttpRequestMessage
{
    Method = HttpMethod.Delete,
    RequestUri = new Uri("http://api.gsped.it/sandbox/Shipment?id=53"),
    Headers =
    {
        { "x-api-key", "YOUR-API-KEY" },
    },
};
using (var response = await client.SendAsync(request))
{
    response.EnsureSuccessStatusCode();
    var body = await response.Content.ReadAsStringAsync();
    Console.WriteLine(body);
}
```

{% endtab %}

{% tab title="cURL" %}

```shell
curl --request DELETE \
  --url 'http://api.gsped.it/sandbox/Shipment?id=53' \
  --header 'x-api-key: YOUR-API-KEY'
```

{% endtab %}
{% endtabs %}

## Shipment - PATCH

This endpoint lets you modify a shipment without having to recreate the label, **ONLY if the shipment has not yet been confirmed.**

{% hint style="info" %}
N.B. This endpoint is valid ONLY for some fields and ONLY for some couriers. See the page of the specific courier for the fields that can be modified.

Fields not allowed for the shipment's courier are rejected with a 400 error.

The user the API key belongs to must have the `crea_spedizione` permission (when permission checks are enabled on the instance).
{% endhint %}

<mark style="color:blue;">`PATCH`</mark> `https://api.gsped.it/[INSTANCE]/Shipment/[idSpedizione]`

Updates a shipment that has not yet been confirmed

#### Headers

| Name                                        | Type   | Description              |
| ------------------------------------------- | ------ | ------------------------ |
| x-api-key<mark style="color:red;">\*</mark> | String | Apikey provided by GSPED |

{% tabs %}
{% tab title="200: OK Shipment information" %}
`result` contains the updated shipment, the same object returned by Shipment GET.

```javascript
{
    "result": {
        // updated shipment (same object as Shipment GET)
    },
    "status": 200
}
```

{% endtab %}

{% tab title="500: Internal Server Error" %}

```json
{
    "result": <messaggioDiErrore>,
    "status": 500
}
```

{% endtab %}

{% tab title="400: Bad Request Input error" %}
Field validation errors (messages are separated by `;` ):

```javascript
{
    "result": "<error messages separated by '; '>",
    "status": 400
}
```

Shipment already confirmed, or courier that does not allow Shipment PATCH:

```javascript
{
    "error": "Impossibile modificare una spedizione già confermata",
    "status": 400
}
```

```javascript
{
    "error": "Il corriere non permette la Shipment PATCH",
    "status": 400
}
```

{% endtab %}

{% tab title="403: Forbidden Invalid apikey" %}

```javascript
{
    "status": false,
    "error": "Invalid API key "
}
```

{% endtab %}

{% tab title="404: Not Found Shipment not found" %}

```javascript
{
    "error": "Spedizione non trovata",
    "status": 404
}
```

{% endtab %}
{% endtabs %}

#### Request Body

It depends on the courier: [SEE HERE](https://apidocs.gsped.com/gsped-api-english-version/spedizioni-e-dintorni/shipment/corrieri)

### Example code snippets

{% tabs %}
{% tab title="PHP" %}

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.gsped.it/sandbox/Shipment/70059765",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "PATCH",
  CURLOPT_POSTFIELDS => "{\"campo\": \"nuovo valore\"}",
  CURLOPT_HTTPHEADER => [
    "x-api-key: YOUR-API-KEY"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
```

{% endtab %}

{% tab title="PYTHON" %}

```python
import http.client
import json

conn = http.client.HTTPSConnection("api.gsped.it")

payload = json.dumps({
  "campo": "nuovo valore"
})

headers = { 'x-api-key': "YOUR-API-KEY" }

conn.request("PATCH", "/sandbox/shipment/70059765", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
```

{% endtab %}

{% tab title="GO" %}

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://api.gsped.it/sandbox/shipment/70059765"

	payload := strings.NewReader("{ \"campo\": \"nuovo valore\" }")

	req, _ := http.NewRequest("PATCH", url, payload)

	req.Header.Add("x-api-key", "YOUR-API-KEY")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

{% endtab %}

{% tab title="C#" %}

```csharp
var client = new HttpClient();
var request = new HttpRequestMessage
{
    Method = HttpMethod.Patch,
    RequestUri = new Uri("https://api.gsped.it/sandbox/shipment/70059765"),
    Headers =
    {
        { "x-api-key", "YOUR-API-KEY" },
    },
    Content = new StringContent("{ \"campo\": \"nuovo valore\" }")
    {
        Headers =
        {
            ContentType = new MediaTypeHeaderValue("application/json")
        }
    }
};
using (var response = await client.SendAsync(request))
{
    response.EnsureSuccessStatusCode();
    var body = await response.Content.ReadAsStringAsync();
    Console.WriteLine(body);
}
```

{% endtab %}

{% tab title="cURL" %}

```
curl --request PATCH \
  --url https://api.gsped.it/sandbox/shipment/70059765 \
  --header 'x-api-key: YOUR-API-KEY' \
  --data '{"campo": "nuovo valore"}'
```

{% endtab %}
{% endtabs %}
