> 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/spedizioni-e-dintorni/labels.md).

# Labels

Endpoint che consente di recuperare l'etichetta di uno specifico collo

Restituisce l'etichetta di **un solo collo** di una spedizione, senza scaricare il file con le etichette di tutti i colli.

## Recupera l'etichetta di un collo

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

Il collo si indica per numero **oppure** per codice: i due parametri sono alternativi e indicarli insieme è un errore.

#### Path Parameters

| Name                                             | Type   | Description                 |
| ------------------------------------------------ | ------ | --------------------------- |
| id\_spedizione<mark style="color:red;">\*</mark> | String | ID univoco spedizione Gsped |

#### Query Parameters

| Name          | Type   | Description                                                        |
| ------------- | ------ | ------------------------------------------------------------------ |
| n\_collo      | String | Numero del collo, da 1 al numero di colli della spedizione         |
| codice\_collo | String | Codice del collo; deve essere univoco all'interno della spedizione |

#### Headers

| Name                                        | Type   | Description             |
| ------------------------------------------- | ------ | ----------------------- |
| x-api-key<mark style="color:red;">\*</mark> | String | APIKEY fornita da Gsped |

{% tabs %}
{% tab title="200: OK Etichetta del collo" %}

```javascript
{
  "status": 200,
  "response": {
    "id_sped": 1234,
    "id_collo": 2,
    "labels": {
      "zpl": "^XA...^XZ",
      "pdf": "JVBERi0xLjQK..."
    }
  }
}
```

{% endtab %}

{% tab title="400: Bad Request Collo non indicato" %}

```javascript
{
  "status": 400,
  "errors": [
    "Collo non indicato: serve n_collo oppure codice_collo"
  ],
  "response": []
}
```

{% endtab %}

{% tab title="400: Bad Request Parametri in conflitto" %}

```javascript
{
  "status": 400,
  "errors": [
    "Indicare n_collo oppure codice_collo, non entrambi"
  ],
  "response": []
}
```

{% endtab %}

{% tab title="400: Bad Request Codice collo non univoco" %}

```javascript
{
  "status": 400,
  "errors": [
    "Codice collo non univoco per la spedizione"
  ],
  "response": []
}
```

{% endtab %}

{% tab title="404: Not Found Spedizione non trovata" %}

```javascript
{
  "status": 404,
  "errors": [
    "Spedizione non trovata"
  ],
  "response": []
}
```

{% endtab %}

{% tab title="404: Not Found Etichetta non disponibile" %}

```javascript
{
  "status": 404,
  "errors": [
    "Etichetta non disponibile per il collo indicato"
  ],
  "response": []
}
```

{% endtab %}

{% tab title="403: Forbidden Apikey invalida" %}

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

{% endtab %}
{% endtabs %}

Il **PDF** è codificato in base64, lo **ZPL** è restituito come testo. Se per quel collo è disponibile solo lo ZPL, il PDF viene prodotto convertendolo; se manca anche quello, il campo resta vuoto.

{% hint style="warning" %}
Alcuni corrieri non salvano un'etichetta per ogni collo, ma un unico file con le etichette di tutta la spedizione. Per quelle spedizioni l'endpoint restituisce quel file quando si chiede il primo collo, e risponde 404 sui colli successivi.
{% endhint %}

#### Snippets codice di esempio

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

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.gsped.it/sandbox/labels/1234?n_collo=2",
  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/labels/1234?n_collo=2", 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/labels/1234?n_collo=2"

	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/labels/1234?n_collo=2"),
    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" %}

```bash
curl --request GET \
  --url 'https://api.gsped.it/sandbox/labels/1234?n_collo=2' \
  --header 'x-api-key: YOUR-API-KEY'
```

{% endtab %}
{% endtabs %}
