# Shipment Confirm

Con questa operazione si conferma che le spedizioni generate sono corrette e sono in processo di affido al corriere / corrieri.

Sull'interfaccia di Gsped le spedizioni confermate vengono spostate dalla sezione **Spedizioni in partenza** alla sezione **Spedizioni partite.**

L'operazione di conferma può essere eseguita in due modalità :&#x20;

* **Indicando l'anagrafica di bollettazione ( client\_id ) :** In questo caso verranno confermate tutte le spedizioni del client\_id indicato.
* **Indicando l'elenco di spedizioni ( ID spedizioni ) :** In questo caso verranno confermate le singole spedizioni specificate.

{% hint style="info" %}
**ATTENZIONE :** \
Nell'operazione di conferma vi viene restituito codice HTTP 200 anche quando le spedizioni non vengono effettivamente confermate nei seguenti casi :&#x20;

* Si tenta di confermare spedizioni già confermate
* Si tenta di confermare spedizioni in errore e/o ancora in fase di elaborazione

Fare attenzione al messaggio restituito nel campo **status,** in quanto qui verranno indicate quante spedizioni sono state confermate e quante no, Esempio : \
\&#xNAN;**"10 spedizioni confermate, 2 errori"**

Nel caso vi siano spedizioni che non siamo stato in grado di confermare, nel array **errors** verranno indicate le spedizioni che non sono state conferma.
{% endhint %}

**Nota :** In questa operazione è possibile richiedere che venga generato il borderò (manifest) da presentare al corriere all'atto del ritiro della merce.

## Conferma delle spedizioni e generazione del borderò (opzionale)

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

#### Headers

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

#### Request Body

| Name                                         | Type    | Description                                                                                                                                           |
| -------------------------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| client\_id<mark style="color:red;">\*</mark> | Integer | Valore comunicato da Gsped (In alternativa al parametro id)                                                                                           |
| id<mark style="color:red;">\*</mark>         | Array   | Elenco di IDs numerici delle spedizioni da confermare (In alternativa a client\_id)                                                                   |
| create\_manifest                             | String  | <p>Valori ammissibili Y o N.<br>Se Y nella risposta verrà incluso il campo manifest che conterrà il PDF del manifest delle spedizioni confermate.</p> |

{% tabs %}
{% tab title="200: OK Operazione eseguita con successo." %}

```javascript
{
  "status": "25 spedizioni confermate, 0 errori",
  "errors": [],
  "manifest": "JVBERi0xLjMKM......UVPRgo=",
  "manifest_id": 10006
}
```

{% endtab %}

{% tab title="400: Bad Request Richiesta mal formata" %}

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

{% endtab %}

{% tab title="403: Forbidden Api Key errata" %}

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

{% endtab %}
{% endtabs %}

#### **Snippets codice di esempio :**

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

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
    CURLOPT_URL => 'https://api.gsped.it/sandbox/shipmentConfirm',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS =>'{
  "create_manifest" : "Y",
  "id": [
    "12345",
    "12346",
    "12347"
  ]
}',
    CURLOPT_HTTPHEADER => array(
        'Content-Type: application/json',
        'x-api-key: YOUR-API-KEY'
    ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;php
```

{% endtab %}

{% tab title="Python" %}

```python
import http.client
import json

conn = http.client.HTTPSConnection("api.gsped.it")
payload = json.dumps({
  "create_manifest": "Y",
  "id": [
    "12345",
    "12346",
    "12347"
  ]
})
headers = {
  'Content-Type': 'application/json',
  'x-api-key': 'YOUR-API-KEY'
}
conn.request("POST", "/sandbox/shipmentConfirm", 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/shipmentConfirm"
  method := "POST"

  payload := strings.NewReader(`{
  "create_manifest" : "Y",
  "id": [
    "12345",
    "12346",
    "12347"
  ]
}`)

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

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("Content-Type", "application/json")
  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 client = new HttpClient();
var request = new HttpRequestMessage
{
    Method = HttpMethod.Post,
    RequestUri = new Uri("https://api.gsped.it/sandbox/shipmentConfirm"),
    Headers =
    {
        { "x-api-key", "YOUR-API-KEY" },
    },
    Content = new StringContent("{\n  \"create_manifest\" : \"Y\",\n  \"id\": [\n    \"12345\",\n    \"12346\",\n    \"12347\"\n  ]\n}")
    {
        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 --location --request POST 'https://api.gsped.it/sandbox/shipmentConfirm' \
--header 'Content-Type: application/json' \
--header 'x-api-key: YOUR-API-KEY' \
--data-raw '{
  "create_manifest" : "Y",
  "id": [
    "12345",
    "12346",
    "12347"
  ]
}'
```

{% endtab %}
{% endtabs %}

####


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://apidocs.gsped.com/spedizioni-e-dintorni/shipment-confirm.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
