# Dettaglio abbonamento

Ritorna i dati dell'abbonamento indicato: importo addebitato a ogni cadenza, data di inizio, stato, metodo di pagamento, coordinate di addebito e rate collegate.
L'identificativo si ottiene dall'endpoint [Elenco abbonamenti](/riferimento-api/abbonamenti/elenco-abbonamenti).

## Richiesta Http

```bash
GET https://api.jatapay.it/abbonamenti/ID_ABBONAMENTO
```

## Parametri di percorso

| Parametro | Richiesto | Tipo |  Descrizione |
| -------------- | -------------- | -------------- |-------------- |
| id_abbonamento   | Sì |  string  |  Identificativo dell'abbonamento (`_id` restituito dall'elenco)   |

**shell**

```bash
curl -X GET "https://api.jatapay.it/abbonamenti/ID_ABBONAMENTO" \
  -H "Authorization: Bearer IL_TOKEN_DI_ACCESSO"
```

**PHP**

```php
$token = 'IL_TOKEN_DI_ACCESSO';

$url = curl_init("https://api.jatapay.it/abbonamenti/ID_ABBONAMENTO");
$authorization = "Authorization: Bearer ".$token;
curl_setopt($url, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($url, CURLOPT_RETURNTRANSFER, true);
curl_setopt($url, CURLOPT_HTTPHEADER, array(
    $authorization
));

$result = curl_exec($url);
curl_close($url);
$api_response = json_decode($result);
```

**Python**

```python
import requests

token = "IL_TOKEN_DI_ACCESSO"

headers = {
    "Authorization": "Bearer " + token
}

response = requests.get("https://api.jatapay.it/abbonamenti/ID_ABBONAMENTO", headers=headers)

print(response.status_code)
print(response.json())
```

**Node.js**

```javascript
const token = 'IL_TOKEN_DI_ACCESSO';

const response = await fetch('https://api.jatapay.it/abbonamenti/ID_ABBONAMENTO', {
  method: 'GET',
  headers: {
    'Authorization': `Bearer ${token}`
  }
});

console.log(response.status, await response.json());
```

**Go**

```go
package main

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

func main() {
	const token = "IL_TOKEN_DI_ACCESSO"

	req, err := http.NewRequest("GET", "https://api.jatapay.it/abbonamenti/ID_ABBONAMENTO", nil)
	if err != nil {
		panic(err)
	}
	req.Header.Set("Authorization", "Bearer "+token)

	res, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()

	data, err := io.ReadAll(res.Body)
	if err != nil {
		panic(err)
	}

	fmt.Println(res.StatusCode, string(data))
}
```

**.NET**

```csharp
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        const string token = "IL_TOKEN_DI_ACCESSO";

        using var client = new HttpClient();
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

        var response = await client.GetAsync("https://api.jatapay.it/abbonamenti/ID_ABBONAMENTO");

        Console.WriteLine((int)response.StatusCode);
        Console.WriteLine(await response.Content.ReadAsStringAsync());
    }
}
```

**Java**

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        String token = "IL_TOKEN_DI_ACCESSO";

        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create("https://api.jatapay.it/abbonamenti/ID_ABBONAMENTO"))
                .header("Authorization", "Bearer " + token)
                .GET()
                .build();

        HttpResponse<String> response = HttpClient.newHttpClient()
                .send(request, HttpResponse.BodyHandlers.ofString());

        System.out.println(response.statusCode());
        System.out.println(response.body());
    }
}
```

## Risposta

La risposta è l'oggetto dell'abbonamento, con lo schema `Abbonamento` e tutti i campi del modello dati.
Il campo `pagamenti` elenca i pagamenti figli dell'abbonamento.

```json
{
  "_id": "6ad9de671d7bc659f6125dac",
  "importo": 48700,
  "data_inizio": "2026-10-22T11:59",
  "stato": "attiva",
  "note": "",
  "stripe": {},
  "payment_method": "sdd",
  "callback_url": "",
  "vendor": "stripe",
  "no_billing": true,
  "data_inserimento": "2026-10-22T09:59",
  "numero": 675,
  "numero_txt": "675",
  "external_vendor_id": "",
  "cliente": "6a218ca738c301f9262b9017",
  "esercente": "6a55ecdfb180394de3e29aa5",
  "iban": "6ad9de92ee0a0643973ffc9f",
  "pagamenti": [
    {
      "_id": "6ae07f601d7bc659f6125dcd",
      "tipo": "rata_abbonamento",
      "importo": 48700,
      "abbonamento": "6ad9de671d7bc659f6125dac",
      "numero": 1,
      "numero_txt": "1",
      "data_pagamento": "",
      "stato": "unpaid",
      "payment_method": "sdd",
      "cliente": "6a218ca738c301f9262b9017",
      "esercente": "6a55ecdfb180394de3e29aa5"
    }
  ]
}
```

## Errori

| Codice | Descrizione |
| -------------- | -------------- |
| 400 | Richiesta non valida, parametri mancanti o non coerenti |
| 401 | Token mancante, scaduto o non valido |
| 403 | Ruolo non abilitato all'operazione |
| 500 | Errore interno del server |

Il corpo della risposta di errore contiene sempre `error_code` (il codice simbolico dell'errore, ad esempio `bad_request`, oppure il codice HTTP corrispondente) e `error_message` con il messaggio descrittivo:

```json
{
  "error_code": "bad_request",
  "error_message": "Messaggio di errore"
}
```

:::warning
La richiesta deve avere l'header `Authorization: Bearer <token>` e, quando è presente un corpo, l'header `Content-Type: application/json`.
:::
