# Orders

This endpoint is used to load the orders and their details on Gsped. It processes the orders via API or web interface and, consequently, generates the the shipment labels.

This endpoint is very useful if there are multiple points of order processing that use the Gsped web interface and it is not possible to activate a specific connector for the download of the orders.

## Retrieve an order with details

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

Retrieve an order with its details from Gsped

#### Headers

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

{% tabs %}
{% tab title="200: OK Response: Successful order retrieved" %}

```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 Response: invalid apikey" %}

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

{% endtab %}

{% tab title="404 Responde: order not found" %}

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

{% endtab %}
{% endtabs %}

#### Snippets example code

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

## Order uploading and details

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

To upload the orders and their details on Gsped

#### Headers

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

#### Request Body

| Name                                         | Type   | Description                                        |
| -------------------------------------------- | ------ | -------------------------------------------------- |
| client\_id<mark style="color:red;">\*</mark> | Int    | Client ID Gsped                                    |
| order\_ref<mark style="color:red;">\*</mark> | String | Order reference                                    |
| name<mark style="color:red;">\*</mark>       | String | Recipient name                                     |
| address<mark style="color:red;">\*</mark>    | String | Recipient address                                  |
| city<mark style="color:red;">\*</mark>       | String | Recipient city                                     |
| zip<mark style="color:red;">\*</mark>        | String | Recipient zipcode                                  |
| province<mark style="color:red;">\*</mark>   | String | Province and Country                               |
| country<mark style="color:red;">\*</mark>    | String | Country code iso 2 char                            |
| email<mark style="color:red;">\*</mark>      | String | Recipient e-mail address                           |
| phone<mark style="color:red;">\*</mark>      | String | Phone number                                       |
| cod                                          | Float  | Value of the stamp                                 |
| insurance                                    | Float  | Amount of the insurance                            |
| notes                                        | String | Order notes                                        |
| warehouse                                    | String | Warehouse                                          |
| rows.description                             | String | Order details description                          |
| rows.sku                                     | String | SKU details                                        |
| rows.qty                                     | Int    | Details quantity                                   |
| invoice\_date                                | String | Order's invoice date                               |
| invoice\_number                              | String | Order's invoice number                             |
| rows.country\_of\_origin                     | String | Country code iso 2 char of the origin of the goods |
| rows.hs\_code                                | String | Row hs code                                        |

{% tabs %}
{% tab title="200: OK Response: Successful order upload" %}

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

{% endtab %}

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

```javascript
{
  "status": "FAILED",
  "error": "Order data not given or in the wrong format"
}
```

{% endtab %}

{% tab title="403: Forbidden Response: invalid apikey" %}

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

{% endtab %}
{% endtabs %}

#### Snippets example code

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

## Update an order with details

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

Update an existing order with its details on Gsped

#### Headers

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

#### Request Body

| Name                                         | Type   | Description                                        |
| -------------------------------------------- | ------ | -------------------------------------------------- |
| client\_id<mark style="color:red;">\*</mark> | String | Client ID Gsped                                    |
| cod                                          | Float  | Value of the stamp                                 |
| phone<mark style="color:red;">\*</mark>      | String | Phone number                                       |
| email<mark style="color:red;">\*</mark>      | String | Recipient e-mail address                           |
| country<mark style="color:red;">\*</mark>    | String | Country code iso 2 char                            |
| province<mark style="color:red;">\*</mark>   | String | Province and Country                               |
| zip<mark style="color:red;">\*</mark>        | String | Recipient zipcode                                  |
| city<mark style="color:red;">\*</mark>       | String | Recipient city                                     |
| address<mark style="color:red;">\*</mark>    | String | Recipient address                                  |
| name<mark style="color:red;">\*</mark>       | String | Recipient name                                     |
| order\_ref<mark style="color:red;">\*</mark> | String | Order reference                                    |
| rows.description                             | String | Order details description                          |
| warehouse                                    | String | Warehouse                                          |
| notes                                        | String | Order notes                                        |
| invoice\_number                              | String | Order's invoice number                             |
| invoice\_date                                | String | Order's invoice date                               |
| insurance                                    | Float  | Amount of the insurance                            |
| rows.sku                                     | String | SKU details                                        |
| rows.qty                                     | Int    | Details quantity                                   |
| rows.country\_of\_origin                     | String | Country code iso 2 char of the origin of the goods |
| rows.hs\_code                                | String | Row hs code                                        |

{% tabs %}
{% tab title="200: OK Response: Successful order upload" %}

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

{% endtab %}

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

```json
{
  "status": "FAILED",
  "error": "Order data not given or in the wrong format"
}
```

{% endtab %}

{% tab title="403: Forbidden Response: invalid apikey" %}

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

{% endtab %}
{% endtabs %}
