# Orders

Questo endpoint serve a caricare ordini e relativi dettagli su Gsped per permetterne l'evasione via API o via interfaccia web con conseguente generazione delle etichette di spedizione.

Molto utile quando ci si trova a dover gestire diversi punti di evasione ordini che utilizzano l'interfaccia web di Gsped ma per cui non è possibile attivare un connettore per lo scarico automatico degli ordini.

## Recupera listato ordini

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

#### Headers

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

#### Query Parameters

<table><thead><tr><th width="177">Name</th><th width="209">Type</th><th>Description</th></tr></thead><tbody><tr><td>id</td><td>int[]</td><td>seleziona se id IN [id, id, ...]</td></tr><tr><td>client_id</td><td>int[]</td><td>seleziona se client_id IN [client_id, client_id, ...]<br><br>Eventuali client_id errati o non permessi verranno ignorati</td></tr><tr><td>order_ref</td><td>string[]</td><td>seleziona se order_ref IN [order_ref, order_ref, ...]<br><br>Ogni stringa max 50 char</td></tr><tr><td>email</td><td>string</td><td>seleziona se email = email<br><br>Max 50 char</td></tr><tr><td>data_ordine_da</td><td>Y-m-d</td><td>Seleziona se data_ordine ≥ data_ordine_da</td></tr><tr><td>data_ordine_a</td><td>Y-m-d</td><td>Seleziona se data_ordine &#x3C;= data_ordine_a</td></tr><tr><td>status</td><td>string[]</td><td>seleziona se status IN [status, status, ...]<br><br>Max 3 char</td></tr><tr><td>exclude_status</td><td>string[]</td><td>seleziona se status NOT IN [status, status, ...]<br><br>Max 3 char</td></tr><tr><td>corriere</td><td>int[]</td><td>seleziona se corriere IN [corriere, corriere, ...]</td></tr><tr><td>exclude_corriere</td><td>int[]</td><td>seleziona se corriere NOT IN [corriere, corriere, ...]</td></tr><tr><td>invoice_number</td><td>string[]</td><td>seleziona se invoice_number IN [invoice_number, invoice_number, ...]</td></tr><tr><td>invoice_date_da</td><td>Y-m-d</td><td>Seleziona se invoice_date ≥ invoice_date_da</td></tr><tr><td>invoice_date_a</td><td>Y-m-d</td><td>Seleziona se invoice_date &#x3C;= invoice_date_a</td></tr><tr><td>withDetails</td><td>1 | 0</td><td>Se 1 ritorna anche i dettagli dell'ordine</td></tr><tr><td>perPage</td><td>1...100</td><td>numero di risultati per pagina richiesti</td></tr><tr><td>page</td><td>int</td><td>numero di pagina richiesta</td></tr><tr><td>orderBy</td><td>id | client_id | order_ref | email | data_ordine | status | corriere | invoice_number | invoice_date</td><td>nome del campo su cui ordinare (default id)</td></tr><tr><td>order</td><td>ASC | DESC</td><td>verso dell'ordinamento (default DESC)</td></tr></tbody></table>

{% tabs %}
{% tab title="200 OK" %}

```json
{
    "status": 200,
    "errors": [],
    "response": {
        "gType": "list",
        "resource": "ordini",
        "page": "1",
        "totPages": 440,
        "totEntries": 879,
        "entries": 2,
        "ordini": [
            {
                "address": "1 Central Park S, Apartment 507",
                "city": "New York",
                "client_id": "390",
                "contrassegno": "0.00",
                "country_code": "US",
                "corriere": "0",
                "valuta": "EUR",
                "valore_doganale": "150.000",
                "email": "test@test.com",
                "id": "879",
                "assicurazione": "0.00",
                "generic1": null,
                "generic2": null,
                "generic3": null,
                "generic4": null,
                "generic5": null,
                "generic6": null,
                "generic7": null,
                "generic8": null,
                "generic9": null,
                "generic10": null,
                "invoice_date": null,
                "invoice_number": null,
                "name": "Markus Schmid",
                "note": "",
                "order_ref": "TEST_NUOVO_FEDEX",
                "phone": "1123521455",
                "prov": "NY",
                "servizio": "0",
                "tag1": "gsped",
                "totale_lordo": "150.00",
                "vat_code": null,
                "cap": "10019",
                "data_ordine": "2025-02-03 00:00:00",
                "status": "1.0"
            },
            {
                "address": "Rosenweg 6",
                "city": "Feusisberg",
                "client_id": "390",
                "contrassegno": "0.00",
                "country_code": "CH",
                "corriere": "0",
                "valuta": "EUR",
                "valore_doganale": "150.000",
                "email": "test@test.com",
                "id": "878",
                "assicurazione": "0.00",
                "generic1": null,
                "generic2": null,
                "generic3": null,
                "generic4": null,
                "generic5": null,
                "generic6": null,
                "generic7": null,
                "generic8": null,
                "generic9": null,
                "generic10": null,
                "invoice_date": null,
                "invoice_number": null,
                "name": "Markus Schmid",
                "note": "",
                "order_ref": "TEST_NUOVO_FEDEX",
                "phone": "123123123",
                "prov": "FA",
                "servizio": "0",
                "tag1": "gsped",
                "totale_lordo": "150.00",
                "vat_code": null,
                "cap": "8835",
                "data_ordine": "2025-01-31 00:00:00",
                "status": "1.0"
            }
        ],
        "previousPageUrl": null,
        "nextPageUrl": "https://api.gsped.it/testbed/orders?perPage=2&page=2&totEntries=879"
    }
}
```

{% endtab %}

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

```json
{
    "status": 400,
    "errors": [
        "The selected order is invalid. (0)"
    ]
}
```

{% endtab %}
{% endtabs %}

#### Codici di esempio

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

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.gsped.it/sandbox/orders",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => [
    "Content-Type: application/json",
    "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 = {
    'Content-Type': "application/json",
    'x-api-key': "YOUR-API-KEY"
    }

conn.request("GET", "/sandbox/orders", 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/orders"

	payload := strings.NewReader("")

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

	req.Header.Add("Content-Type", "application/json")
	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/orders"),
    Headers =
    {
        { "x-api-key", "YOUR-API-KEY" },
    },
    Content = new StringContent("")
    {
        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" %}

```bash
curl --request GET \
  --url https://api.gsped.it/sandbox/orders \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: YOUR-API-KEY'
```

{% endtab %}
{% endtabs %}

## Recupera un ordine e dettagli

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

Recupera un ordine e i relativi dettagli da Gsped

#### Headers

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

{% tabs %}
{% tab title="200: OK Risposta recupero avvenuto" %}

```json
{
    "address": "piazza ambrosoli 13",
    "city": "alessandria",
    "client_id": 390,
    "cod": 123.45,
    "country": "IT",
    "currency": "EUR",
    "customs_value": 123.45,
    "email": "pippo@pippo.it",
    "id": 1,
    "insurance": 123.45,
    "invoice_date": "2023-06-05",
    "invoice_number": 12345678,
    "name": "mario rossi",
    "notes": "testo delle note",
    "order_ref": "ordrif56780",
    "phone": 1311750253,
    "province": "AL",
    "rows": [
        {
            "country_of_origin": "DE",
            "description": "Descrizione riga ordine",
            "qty": 1,
            "sku": "art3",
        }
    ],
    "total": 0,
    "warehouse": "",
    "zip": 15121
}
```

{% endtab %}

{% tab title="403: Forbidden Risposta apikey errata" %}

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

{% endtab %}

{% tab title="404 Risposta ordine non trovato" %}

```json
{
    "error": "Ordine non trovato",
    "code": 404
}
```

{% endtab %}
{% endtabs %}

#### Snippets codice di esempio

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

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.gsped.it/sandbox/orders/1",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => [
    "Content-Type: application/json",
    "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 = {
    'Content-Type': "application/json",
    'x-api-key': "YOUR-API-KEY"
    }

conn.request("GET", "/sandbox/orders/1", 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/orders/1"

	payload := strings.NewReader("")

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

	req.Header.Add("Content-Type", "application/json")
	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/orders/1"),
    Headers =
    {
        { "x-api-key", "YOUR-API-KEY" },
    },
    Content = new StringContent("")
    {
        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" %}

```bash
curl --request GET \
  --url https://api.gsped.it/sandbox/orders/1 \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: YOUR-API-KEY'
```

{% endtab %}
{% endtabs %}

## Caricamento ordini e dettagli

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

Permette di caricare gli ordini ed i relativi dettagli su Gsped

#### Headers

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

#### Request Body

<table><thead><tr><th width="226">Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>client_id<mark style="color:red;">*</mark></td><td>Int</td><td>Client ID Gsped</td></tr><tr><td>zip<mark style="color:red;">*</mark></td><td>String</td><td>Zipcode Destinatario</td></tr><tr><td>city<mark style="color:red;">*</mark></td><td>String</td><td>Città Destinatario</td></tr><tr><td>address<mark style="color:red;">*</mark></td><td>String</td><td>Indirizzo Destinatario</td></tr><tr><td>name<mark style="color:red;">*</mark></td><td>String</td><td>Nome Destinatario</td></tr><tr><td>order_ref<mark style="color:red;">*</mark></td><td>String</td><td>Riferimento ordine</td></tr><tr><td>email<mark style="color:red;">*</mark></td><td>String</td><td>Indirizzo email Destinatario</td></tr><tr><td>country<mark style="color:red;">*</mark></td><td>String</td><td>Country code iso 2 char</td></tr><tr><td>province<mark style="color:red;">*</mark></td><td>String</td><td>Sigla Provincia o Stato</td></tr><tr><td>insurance</td><td>Float</td><td>Valore assicurazione</td></tr><tr><td>cod</td><td>Float</td><td>Valore del contrasssegno</td></tr><tr><td>phone<mark style="color:red;">*</mark></td><td>String</td><td>Numero di telefono</td></tr><tr><td>rows.description</td><td>String</td><td>Descrizione dettaglio ordine</td></tr><tr><td>warehouse</td><td>String</td><td>Magazzino</td></tr><tr><td>notes</td><td>String</td><td>Note ordine</td></tr><tr><td>rows.qty</td><td>Int</td><td>Quantità dettaglio</td></tr><tr><td>rows.sku</td><td>String</td><td>SKU dettaglio</td></tr><tr><td>rows.country_of_origin</td><td>String</td><td>Country code iso 2 char di origine della merce</td></tr><tr><td>invoice_date</td><td>String</td><td>Data della fattura dell'ordine</td></tr><tr><td>invoice_number</td><td>String</td><td>Numero della fattura dell'ordine</td></tr><tr><td>rows.hs_code</td><td>String</td><td>HS code dettaglio</td></tr><tr><td>rows.barcode_riga</td><td>String</td><td>Stringa barcode singolo item</td></tr><tr><td>rows.prezzo_singolo</td><td>String</td><td>Prezzo singolo item</td></tr><tr><td>rows.peso_riga</td><td>String</td><td>Peso singolo item</td></tr></tbody></table>

{% tabs %}
{% tab title="200: OK Risposta Caricamento Ordine avvenuto" %}

```javascript
{
  "status": "OK",
  "order_id": 572602
}
```

{% endtab %}

{% tab title="403: Forbidden Risposta apikey errata" %}

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

{% endtab %}

{% tab title="400: Bad Request Payload Errato" %}

```javascript
{
  "status": "FAILED",
  "error": "Dati ordine non presenti o in formato sbagliato"
}
```

{% endtab %}
{% endtabs %}

#### Snippets codice di esempio

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

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.gsped.it/sandbox/orders",
  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\": 638,\n  \"order_ref\": \"test-gsped-3\",\n  \"name\": \"mario rossi\",\n  \"address\": \"piazza ambrosoli 13\",\n  \"city\": \"alessandria\",\n  \"zip\": \"15121\",\n  \"province\": \"AL\",\n  \"country\": \"IT\",\n  \"email\": \"pippo@pippo.it\",\n  \"phone\": \"01311750253\",\n  \"cod\": 10,\n  \"insurance\": 0,\n  \"notes\": \"testo delle note\",\n  \"customs_value\": 123.45,\n  \"currency\": \"EUR\",\n  \"warehouse\": \"\",\n  \"tag\" : \"pippo1\",\n  \"rows\": [\n    {\n    \t\"description\" : \"Cosa rossa 1\",\n      \"sku\": \"art3\",\n      \"qty\": 1\n    },\n    {\n    \t\"description\" : \"Cosa rossa 2\",\n      \"sku\": \"art4\",\n      \"qty\": 2\n    }\n  ]\n}",
  CURLOPT_HTTPHEADER => [
    "Content-Type: application/json",
    "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 = "{\n  \"client_id\": 638,\n  \"order_ref\": \"test-gsped-3\",\n  \"name\": \"mario rossi\",\n  \"address\": \"piazza ambrosoli 13\",\n  \"city\": \"alessandria\",\n  \"zip\": \"15121\",\n  \"province\": \"AL\",\n  \"country\": \"IT\",\n  \"email\": \"pippo@pippo.it\",\n  \"phone\": \"01311750253\",\n  \"cod\": 10,\n  \"insurance\": 0,\n  \"notes\": \"testo delle note\",\n  \"customs_value\": 123.45,\n  \"currency\": \"EUR\",\n  \"warehouse\": \"\",\n  \"tag\" : \"pippo1\",\n  \"rows\": [\n    {\n    \t\"description\" : \"Cosa rossa 1\",\n      \"sku\": \"art3\",\n      \"qty\": 1\n    },\n    {\n    \t\"description\" : \"Cosa rossa 2\",\n      \"sku\": \"art4\",\n      \"qty\": 2\n    }\n  ]\n}"

headers = {
    'Content-Type': "application/json",
    'x-api-key': "YOUR-API-KEY"
    }

conn.request("POST", "/sandbox/orders", 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/orders"

	payload := strings.NewReader("{\n  \"client_id\": 638,\n  \"order_ref\": \"test-gsped-3\",\n  \"name\": \"mario rossi\",\n  \"address\": \"piazza ambrosoli 13\",\n  \"city\": \"alessandria\",\n  \"zip\": \"15121\",\n  \"province\": \"AL\",\n  \"country\": \"IT\",\n  \"email\": \"pippo@pippo.it\",\n  \"phone\": \"01311750253\",\n  \"cod\": 10,\n  \"insurance\": 0,\n  \"notes\": \"testo delle note\",\n  \"customs_value\": 123.45,\n  \"currency\": \"EUR\",\n  \"warehouse\": \"\",\n  \"tag\" : \"pippo1\",\n  \"rows\": [\n    {\n    \t\"description\" : \"Cosa rossa 1\",\n      \"sku\": \"art3\",\n      \"qty\": 1\n    },\n    {\n    \t\"description\" : \"Cosa rossa 2\",\n      \"sku\": \"art4\",\n      \"qty\": 2\n    }\n  ]\n}")

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

	req.Header.Add("Content-Type", "application/json")
	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#" %}

```c
var client = new HttpClient();
var request = new HttpRequestMessage
{
    Method = HttpMethod.Post,
    RequestUri = new Uri("https://api.gsped.it/sandbox/orders"),
    Headers =
    {
        { "x-api-key", "YOUR-API-KEY" },
    },
    Content = new StringContent("{\n  \"client_id\": 638,\n  \"order_ref\": \"test-gsped-3\",\n  \"name\": \"mario rossi\",\n  \"address\": \"piazza ambrosoli 13\",\n  \"city\": \"alessandria\",\n  \"zip\": \"15121\",\n  \"province\": \"AL\",\n  \"country\": \"IT\",\n  \"email\": \"pippo@pippo.it\",\n  \"phone\": \"01311750253\",\n  \"cod\": 10,\n  \"insurance\": 0,\n  \"notes\": \"testo delle note\",\n  \"customs_value\": 123.45,\n  \"currency\": \"EUR\",\n  \"warehouse\": \"\",\n  \"tag\" : \"pippo1\",\n  \"rows\": [\n    {\n    \t\"description\" : \"Cosa rossa 1\",\n      \"sku\": \"art3\",\n      \"qty\": 1\n    },\n    {\n    \t\"description\" : \"Cosa rossa 2\",\n      \"sku\": \"art4\",\n      \"qty\": 2\n    }\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" %}

```bash
curl --request POST \
  --url https://api.gsped.it/sandbox/orders \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: YOUR-API-KEY' \
  --data '{
  "client_id": 638,
  "order_ref": "test-gsped-3",
  "name": "mario rossi",
  "address": "piazza ambrosoli 13",
  "city": "alessandria",
  "zip": "15121",
  "province": "AL",
  "country": "IT",
  "email": "pippo@pippo.it",
  "phone": "01311750253",
  "cod": 10,
  "insurance": 0,
  "notes": "testo delle note",
  "customs_value": 123.45,
  "currency": "EUR",
  "warehouse": "",
  "tag" : "pippo1",
  "rows": [
    {
    	"description" : "Cosa rossa 1",
      "sku": "art3",
      "qty": 1
    },
    {
    	"description" : "Cosa rossa 2",
      "sku": "art4",
      "qty": 2
    }
  ]
}'
```

{% endtab %}
{% endtabs %}

## Modifica ordini e dettagli di ordine esistente

<mark style="color:purple;">`PATCH`</mark> `https://api.gsped.it/[ISTANZA]/Orders/[ID_ORDINE]`

Permette di modificare un ordine ed i relativi dettagli su Gsped

#### Headers

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

#### Request Body

| Name                                         | Type   | Description                                    |
| -------------------------------------------- | ------ | ---------------------------------------------- |
| client\_id<mark style="color:red;">\*</mark> | Int    | Client ID Gsped                                |
| name<mark style="color:red;">\*</mark>       | String | Nome Destinatario                              |
| order\_ref<mark style="color:red;">\*</mark> | String | Riferimento ordine                             |
| address<mark style="color:red;">\*</mark>    | String | Indirizzo Destinatario                         |
| cod                                          | Float  | Valore del contrasssegno                       |
| phone<mark style="color:red;">\*</mark>      | String | Numero di telefono                             |
| email<mark style="color:red;">\*</mark>      | String | Indirizzo email Destinatario                   |
| country<mark style="color:red;">\*</mark>    | String | Country code iso 2 char                        |
| province<mark style="color:red;">\*</mark>   | String | Sigla Provincia o Stato                        |
| zip<mark style="color:red;">\*</mark>        | String | Zipcode Destinatario                           |
| city<mark style="color:red;">\*</mark>       | String | Città Destinatario                             |
| rows.description                             | String | Descrizione dettaglio ordine                   |
| warehouse                                    | String | Magazzino                                      |
| notes                                        | String | Note ordine                                    |
| invoice\_number                              | String | Numero della fattura dell'ordine               |
| invoice\_date                                | String | Data della fattura dell'ordine                 |
| insurance                                    | Float  | Valore assicurazione                           |
| rows.hs\_code                                | String | HS code dettaglio                              |
| rows.qty                                     | Int    | Quantità dettaglio                             |
| rows.sku                                     | String | SKU dettaglio                                  |
| rows.country\_of\_origin                     | String | Country code iso 2 char di origine della merce |

{% tabs %}
{% tab title="200: OK Risposta Modifica Ordine avvenuto" %}

```json
{
  "status": "OK",
  "order_id": 572602
}
```

{% endtab %}

{% tab title="400: Bad Request Payload Errato" %}

```json
{
  "status": "FAILED",
  "error": "Dati ordine non presenti o in formato sbagliato"
}
```

{% endtab %}

{% tab title="403: Forbidden Risposta apikey errata" %}

```json
{
  "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, [
  CURLOPT_URL => "https://api.gsped.it/sandbox/orders/1",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "PATCH",
  CURLOPT_POSTFIELDS => "{\n  \"client_id\": 638,\n  \"order_ref\": \"test-gsped-3\",\n  \"name\": \"mario rossi\",\n  \"address\": \"piazza ambrosoli 13\",\n  \"city\": \"alessandria\",\n  \"zip\": \"15121\",\n  \"province\": \"AL\",\n  \"country\": \"IT\",\n  \"email\": \"pippo@pippo.it\",\n  \"phone\": \"01311750253\",\n  \"cod\": 10,\n  \"insurance\": 0,\n  \"notes\": \"testo delle note\",\n  \"customs_value\": 123.45,\n  \"currency\": \"EUR\",\n  \"warehouse\": \"\",\n  \"tag\" : \"pippo1\",\n  \"rows\": [\n    {\n    \t\"description\" : \"Cosa rossa 1\",\n      \"sku\": \"art3\",\n      \"qty\": 1\n    },\n    {\n    \t\"description\" : \"Cosa rossa 2\",\n      \"sku\": \"art4\",\n      \"qty\": 2\n    }\n  ]\n}",
  CURLOPT_HTTPHEADER => [
    "Content-Type: application/json",
    "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 = "{\n  \"client_id\": 638,\n  \"order_ref\": \"test-gsped-3\",\n  \"name\": \"mario rossi\",\n  \"address\": \"piazza ambrosoli 13\",\n  \"city\": \"alessandria\",\n  \"zip\": \"15121\",\n  \"province\": \"AL\",\n  \"country\": \"IT\",\n  \"email\": \"pippo@pippo.it\",\n  \"phone\": \"01311750253\",\n  \"cod\": 10,\n  \"insurance\": 0,\n  \"notes\": \"testo delle note\",\n  \"customs_value\": 123.45,\n  \"currency\": \"EUR\",\n  \"warehouse\": \"\",\n  \"tag\" : \"pippo1\",\n  \"rows\": [\n    {\n    \t\"description\" : \"Cosa rossa 1\",\n      \"sku\": \"art3\",\n      \"qty\": 1\n    },\n    {\n    \t\"description\" : \"Cosa rossa 2\",\n      \"sku\": \"art4\",\n      \"qty\": 2\n    }\n  ]\n}"

headers = {
    'Content-Type': "application/json",
    'x-api-key': "YOUR-API-KEY"
    }

conn.request("PATCH", "/sandbox/orders/1", 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/orders/1"

	payload := strings.NewReader("{\n  \"client_id\": 638,\n  \"order_ref\": \"test-gsped-3\",\n  \"name\": \"mario rossi\",\n  \"address\": \"piazza ambrosoli 13\",\n  \"city\": \"alessandria\",\n  \"zip\": \"15121\",\n  \"province\": \"AL\",\n  \"country\": \"IT\",\n  \"email\": \"pippo@pippo.it\",\n  \"phone\": \"01311750253\",\n  \"cod\": 10,\n  \"insurance\": 0,\n  \"notes\": \"testo delle note\",\n  \"customs_value\": 123.45,\n  \"currency\": \"EUR\",\n  \"warehouse\": \"\",\n  \"tag\" : \"pippo1\",\n  \"rows\": [\n    {\n    \t\"description\" : \"Cosa rossa 1\",\n      \"sku\": \"art3\",\n      \"qty\": 1\n    },\n    {\n    \t\"description\" : \"Cosa rossa 2\",\n      \"sku\": \"art4\",\n      \"qty\": 2\n    }\n  ]\n}")

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

	req.Header.Add("Content-Type", "application/json")
	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/orders/1"),
    Headers =
    {
        { "x-api-key", "YOUR-API-KEY" },
    },
    Content = new StringContent("{\n  \"client_id\": 638,\n  \"order_ref\": \"test-gsped-3\",\n  \"name\": \"mario rossi\",\n  \"address\": \"piazza ambrosoli 13\",\n  \"city\": \"alessandria\",\n  \"zip\": \"15121\",\n  \"province\": \"AL\",\n  \"country\": \"IT\",\n  \"email\": \"pippo@pippo.it\",\n  \"phone\": \"01311750253\",\n  \"cod\": 10,\n  \"insurance\": 0,\n  \"notes\": \"testo delle note\",\n  \"customs_value\": 123.45,\n  \"currency\": \"EUR\",\n  \"warehouse\": \"\",\n  \"tag\" : \"pippo1\",\n  \"rows\": [\n    {\n    \t\"description\" : \"Cosa rossa 1\",\n      \"sku\": \"art3\",\n      \"qty\": 1\n    },\n    {\n    \t\"description\" : \"Cosa rossa 2\",\n      \"sku\": \"art4\",\n      \"qty\": 2\n    }\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" %}

```bash
curl --request PATCH \
  --url https://api.gsped.it/sandbox/orders/1 \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: YOUR-API-KEY' \
  --data '{
  "client_id": 638,
  "order_ref": "test-gsped-3",
  "name": "mario rossi",
  "address": "piazza ambrosoli 13",
  "city": "alessandria",
  "zip": "15121",
  "province": "AL",
  "country": "IT",
  "email": "pippo@pippo.it",
  "phone": "01311750253",
  "cod": 10,
  "insurance": 0,
  "notes": "testo delle note",
  "customs_value": 123.45,
  "currency": "EUR",
  "warehouse": "",
  "tag" : "pippo1",
  "rows": [
    {
    	"description" : "Cosa rossa 1",
      "sku": "art3",
      "qty": 1
    },
    {
    	"description" : "Cosa rossa 2",
      "sku": "art4",
      "qty": 2
    }
  ]
}'
```

{% endtab %}
{% endtabs %}

{% hint style="danger" %}
N.B. Non è possibile modificare un ordine nel caso in cui l'ordine sia collegato ad una spedizione già confermata.
{% endhint %}

Comportamento in caso l'ordine sia collegato ad una spedizione da confermare: \
se la spedizione è extraUE e il corriere supporta i CIN se il corriere supporta la shipmentPatch dei dati CIN si esegue l'aggiornamento sul corriere, altrimenti la spedizione verrà messa in errore in quanto dovrà essere rigenerata con i nuovi dati ordine.


---

# 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/gestione-ordini/orders.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.
