> For the complete documentation index, see [llms.txt](https://apidocs.gsped.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://apidocs.gsped.com/spedizioni-e-dintorni/stocks.md).

# Stocks

## Stocks

Questo endpoint permette di ottenere l'elenco delle giacenze.&#x20;

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

#### Query parameters

| Name                                         | Type | Description                                                                       |
| -------------------------------------------- | ---- | --------------------------------------------------------------------------------- |
| client\_id<mark style="color:red;">\*</mark> | int  | ID del cliente (o del cliente fatturato)                                          |
| days                                         | int  | Recupera giacenze aperte negli ultimi X giorni (minimo 1, massimo 90, default 10) |

#### Headers

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

{% tabs %}
{% tab title="200: OK elenco giacenze" %}

```javascript
{
    "status": 200,
    "response": [
        {...},
        {...},
    ]
}
```

{% endtab %}

{% tab title="400: Bad Request Errore input" %}

```javascript
{
  "status": 400,
  "errors": [
    "client_id obbligatorio"
  ],
  "response": []
}
```

{% endtab %}

{% tab title="403: Forbidden Apikey invalida" %}

```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, [
  CURLOPT_URL => "https://api.gsped.it/sandbox/Stocks?client_id=123",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_POSTFIELDS => "",
  CURLOPT_HTTPHEADER => [
    "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 = { 'x-api-key': "YOUR-API-KEY" }

conn.request("GET", "/sandbox/Stocks?client_id=123", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
```

{% endtab %}

{% tab title="GO" %}

```go
package main

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

func main() {

	url := "https://api.gsped.it/sandbox/Stocks?client_id=123"

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

	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
// Some codevar client = new HttpClient();
var request = new HttpRequestMessage
{
    Method = HttpMethod.Get,
    RequestUri = new Uri("https://api.gsped.it/sandbox/Stocks?client_id=123"),
    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" %}

```shell
curl --request GET \
  --url 'https://api.gsped.it/sandbox/Stocks?client_id=123' \
  --header 'x-api-key: YOUR-API-KEY'
```

{% endtab %}
{% endtabs %}
