# Tracking

Endpoint utile per consultare lo status di una spedizione.

E' possibile cercare la spedizione attraverso uno dei seguenti parametri :&#x20;

* **id :** ID della spedizione
* **ddt\_num :** Riferimento numerico della spedizione
* **ddt\_alpha :** Riferimento alfanumerico della spedizione

**Nota bene :** E' indispensabile che venga indicato almeno uno dei parametri appena evidenziati

Nel caso in cui i riferimenti utilizzati nella propria istanza non siano univoci, se si utilizzano il ddt\_num e/o il ddt\_alpha come parametri nella risposta si troverà un array con i dati di tutte le spedizioni corrispondenti ai parametri passati.

## Recupera lo status della spedizione

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

#### Path Parameters

| Name       | Type    | Description                               |
| ---------- | ------- | ----------------------------------------- |
| id         | Integer | ID della spedizione                       |
| ddt\_num   | String  | Riferimento numerico della spedizione     |
| ddt\_alpha | String  | Riferimento alfanumerico della spedizione |

#### Headers

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

{% tabs %}
{% tab title="200: OK Tutto ok" %}

```javascript
{
    "status_code": 19,
    "status": "CONSEGNATO",
    "delivery_date": "2021-03-30 11:00:00",
    "fid_partenza": 2,
    "num_serie": 1,
    "num_spedizione": "0585596",
    "corriere_id": 1,
    "corriere": "BRT",
    "ddt_num": 18795,
    "ddt_alpha": "100027946",
    "client_id": 1,
    "tracking_link": "https://vas.brt.it/vas/sped_det_show.hsm?nspediz=002010585132",
    "id_gsped": 18795
}
```

{% endtab %}

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

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

{% endtab %}

{% tab title="400: Bad Request Non è stato indicato alcun parametro tra i parametri disponibili oppure il campo indicato non è corretto" %}

```javascript
{
    "error": "Riferimento spedizione non indicato"
}
```

{% endtab %}

{% tab title="403: Forbidden Api key utilizzata non valida" %}

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

{% endtab %}
{% endtabs %}

## **Snippets codice di esempio :**&#x20;

Esempi di chiamate utilizzando il campo id

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

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
    CURLOPT_URL => 'https://api.gsped.it/sandbox/tracking?id=18795',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'GET',
    CURLOPT_HTTPHEADER => array(
        'x-api-key: YOUR-API-KEY'
    ),
));

$response = curl_exec($curl);

curl_close($curl);
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/tracking?id=jhon", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))ph
```

{% endtab %}

{% tab title="GO" %}

```go
package main

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

func main() {

  url := "https://api.gsped.it/sandbox/tracking?id=jhon"
  method := "GET"

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, nil)

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("x-api-key", "YOUR-API-KEY")

  res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()

  body, err := ioutil.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  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.Get,
    RequestUri = new Uri("https://api.gsped.it/sandbox/tracking?id=18795"),
    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 --location --request GET 'https://api.gsped.it/sandbox/tracking?id=jhon' \
--header 'x-api-key: YOUR-API-KEY'
```

{% endtab %}
{% endtabs %}
