# Shipment Confirm

This operation confirms that the generated shipments have correctly managed and are going to be given to the courier/s

On the Gsped interface the confirmed shipments are transferred from the section **Outgoing shipments** to the section **Expedition started**

The confirm operation could be performed in two ways :

**Using the labeling data ( client\_id )**. In this case all the shipments of the client\_id will be confirmed. **Using the shipping list ( ID spedizioni )**. In this case the single shipments will be confirmed.

{% hint style="info" %}
**PLEASE NOTE :**\
\*\*\*\*In the confirm operation the HTTP 200 code is returned - even if the shipments are not actually confirmed - in the following situations:

* If you attempt to confirm shipments that have already been confirmed
* If you attempt to confirm with the status **error** and/or shipments that are still in progress.

Pay attention to the message returned in the field **status**; here there will be indicated how many shipments have been confirmed and how many not. Example: "**10 shipments confirmed, 2 errors occurred"**

In case there are shipments we are not able to confirm, in the array **errors** there will be indicated which shipments have not been confirmed.
{% endhint %}

**Please note:** During this operation it is possible to request the creation of the shipping manifest to show the courier at the withdrawal of the goods.

## Shipment confirm and creation of the shipping manifest (additional)

<mark style="color:green;">`POST`</mark> `https://api.gsped.it/[INSTANCE]/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 given by Gsped |

#### Request Body

| Name                                         | Type    | Description                                                                                                                                  |
| -------------------------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| client\_id<mark style="color:red;">\*</mark> | Integer | Value communicated by Gsped (in alternative to the ID parameter)                                                                             |
| id<mark style="color:red;">\*</mark>         | Array   | List of the numeric IDs of the shipments to confirm (in alternative to the client ID)                                                        |
| create\_manifest                             | String  | <p>Accepted values Y or N</p><p>\</p><p>If Y, in the response the field manifest with the PDF of the shipping manifest will be included.</p> |

{% tabs %}
{% tab title="200: OK Operation successfully performed." %}

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

{% endtab %}

{% tab title="400: Bad Request Bad request" %}

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

{% endtab %}

{% tab title="403: Forbidden Invalid Api key" %}

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

{% endtab %}
{% endtabs %}

#### **Example Snippets :**

{% 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 %}

####
