> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wappfy.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Gruppi

> Crea, gestisci e interagisci con i gruppi WhatsApp in modo programmatico.

# Gruppi

Gestisci i gruppi WhatsApp tramite l'API Wappfy. Puoi creare gruppi, gestire i partecipanti, gestire i link di invito e altro ancora.

Tutti gli endpoint dei gruppi sono associati a un'istanza specifica:

```
/api/instances/{instanceId}/groups/...
```

***

## Creare un gruppo

Crea un nuovo gruppo WhatsApp con i partecipanti iniziali.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.wappfy.io/api/instances/inst_abc123/groups \
    -H "X-Api-Key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "Project Alpha",
      "participants": [
        "5511999998888@s.whatsapp.net",
        "5511888887777@s.whatsapp.net"
      ]
    }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch(
    "https://api.wappfy.io/api/instances/inst_abc123/groups",
    {
      method: "POST",
      headers: {
        "X-Api-Key": "YOUR_API_KEY",
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        name: "Project Alpha",
        participants: [
          "5511999998888@s.whatsapp.net",
          "5511888887777@s.whatsapp.net",
        ],
      }),
    }
  );

  const group = await response.json();
  console.log(group.data.group_id);
  ```
</CodeGroup>

**Risposta:**

```json theme={null}
{
  "data": {
    "group_id": "120363012345678901@g.us",
    "name": "Project Alpha",
    "participants": [
      {
        "id": "5511999998888@s.whatsapp.net",
        "is_admin": false
      },
      {
        "id": "5511888887777@s.whatsapp.net",
        "is_admin": false
      }
    ]
  }
}
```

***

## Elencare i gruppi

Recupera tutti i gruppi di cui l'istanza e membro.

<CodeGroup>
  ```bash cURL theme={null}
  curl https://api.wappfy.io/api/instances/inst_abc123/groups \
    -H "X-Api-Key: YOUR_API_KEY"
  ```

  ```javascript Node.js theme={null}
  const response = await fetch(
    "https://api.wappfy.io/api/instances/inst_abc123/groups",
    {
      headers: { "X-Api-Key": "YOUR_API_KEY" },
    }
  );

  const { data } = await response.json();
  console.log(`Found ${data.length} groups`);
  ```
</CodeGroup>

**Risposta:**

```json theme={null}
{
  "data": [
    {
      "group_id": "120363012345678901@g.us",
      "name": "Project Alpha",
      "participant_count": 5
    },
    {
      "group_id": "120363098765432109@g.us",
      "name": "Support Team",
      "participant_count": 12
    }
  ]
}
```

***

## Ottenere informazioni sul gruppo

Recupera informazioni dettagliate su un gruppo specifico.

```bash theme={null}
curl https://api.wappfy.io/api/instances/inst_abc123/groups/120363012345678901@g.us \
  -H "X-Api-Key: YOUR_API_KEY"
```

**Risposta:**

```json theme={null}
{
  "data": {
    "group_id": "120363012345678901@g.us",
    "name": "Project Alpha",
    "description": "Team workspace for Project Alpha",
    "owner": "5511999998888@s.whatsapp.net",
    "created_at": "2026-01-15T10:00:00Z",
    "participants": [
      {
        "id": "5511999998888@s.whatsapp.net",
        "is_admin": true,
        "is_super_admin": true
      },
      {
        "id": "5511888887777@s.whatsapp.net",
        "is_admin": false,
        "is_super_admin": false
      }
    ]
  }
}
```

***

## Aggiornare un gruppo

Aggiorna il nome o la descrizione del gruppo. Devi essere un amministratore del gruppo per eseguire questa azione.

```bash theme={null}
curl -X PATCH https://api.wappfy.io/api/instances/inst_abc123/groups/120363012345678901@g.us \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Project Alpha v2",
    "description": "Updated workspace for Project Alpha"
  }'
```

<Note>
  Solo gli amministratori del gruppo possono aggiornare il nome e la descrizione. Se l'istanza non e un amministratore, verra restituito un errore `403`.
</Note>

***

## Abbandonare un gruppo

Rimuovi l'istanza da un gruppo.

```bash theme={null}
curl -X POST https://api.wappfy.io/api/instances/inst_abc123/groups/120363012345678901@g.us/leave \
  -H "X-Api-Key: YOUR_API_KEY"
```

<Warning>
  Dopo aver abbandonato un gruppo, sara necessario un link di invito o che un altro amministratore ti aggiunga nuovamente.
</Warning>

***

## Partecipanti

### Elencare i partecipanti

Ottieni tutti i partecipanti di un gruppo.

```bash theme={null}
curl https://api.wappfy.io/api/instances/inst_abc123/groups/120363012345678901@g.us/participants \
  -H "X-Api-Key: YOUR_API_KEY"
```

**Risposta:**

```json theme={null}
{
  "data": [
    {
      "id": "5511999998888@s.whatsapp.net",
      "is_admin": true,
      "is_super_admin": true
    },
    {
      "id": "5511888887777@s.whatsapp.net",
      "is_admin": false,
      "is_super_admin": false
    },
    {
      "id": "5511777776666@s.whatsapp.net",
      "is_admin": true,
      "is_super_admin": false
    }
  ]
}
```

### Aggiungere partecipanti

Aggiungi uno o piu partecipanti a un gruppo. Devi essere un amministratore del gruppo.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.wappfy.io/api/instances/inst_abc123/groups/120363012345678901@g.us/participants \
    -H "X-Api-Key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "participants": [
        "5511666665555@s.whatsapp.net",
        "5511555554444@s.whatsapp.net"
      ]
    }'
  ```

  ```javascript Node.js theme={null}
  await fetch(
    "https://api.wappfy.io/api/instances/inst_abc123/groups/120363012345678901@g.us/participants",
    {
      method: "POST",
      headers: {
        "X-Api-Key": "YOUR_API_KEY",
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        participants: [
          "5511666665555@s.whatsapp.net",
          "5511555554444@s.whatsapp.net",
        ],
      }),
    }
  );
  ```
</CodeGroup>

### Rimuovere partecipanti

Rimuovi uno o piu partecipanti da un gruppo. Devi essere un amministratore del gruppo.

```bash theme={null}
curl -X DELETE https://api.wappfy.io/api/instances/inst_abc123/groups/120363012345678901@g.us/participants \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "participants": [
      "5511666665555@s.whatsapp.net"
    ]
  }'
```

***

## Codici di invito

### Ottenere il codice di invito

Genera o recupera il link di invito del gruppo. Devi essere un amministratore del gruppo.

```bash theme={null}
curl https://api.wappfy.io/api/instances/inst_abc123/groups/120363012345678901@g.us/invite-code \
  -H "X-Api-Key: YOUR_API_KEY"
```

**Risposta:**

```json theme={null}
{
  "data": {
    "invite_code": "https://chat.whatsapp.com/AbCdEfGhIjKlMn"
  }
}
```

### Unirsi tramite codice di invito

Unisciti a un gruppo utilizzando un codice di invito.

```bash theme={null}
curl -X POST https://api.wappfy.io/api/instances/inst_abc123/groups/join \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "invite_code": "AbCdEfGhIjKlMn"
  }'
```

<Note>
  Passa solo la parte del codice, non l'URL completo. Per `https://chat.whatsapp.com/AbCdEfGhIjKlMn`, passa `AbCdEfGhIjKlMn`.
</Note>

***

## Inviare messaggi ai gruppi

Per inviare un messaggio a un gruppo, usa l'endpoint standard di [invio messaggi](/it/guides/sending-messages) con l'ID chat del gruppo:

```bash theme={null}
curl -X POST https://api.wappfy.io/api/instances/inst_abc123/messages/send \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "chat_id": "120363012345678901@g.us",
    "type": "text",
    "text": "Hello team!"
  }'
```

Gli ID chat dei gruppi terminano sempre con `@g.us`.

***

## Riferimento degli endpoint

| Metodo   | Endpoint                                            | Descrizione                          |
| -------- | --------------------------------------------------- | ------------------------------------ |
| `POST`   | `/api/instances/{id}/groups`                        | Crea un nuovo gruppo                 |
| `GET`    | `/api/instances/{id}/groups`                        | Elenca tutti i gruppi                |
| `GET`    | `/api/instances/{id}/groups/{groupId}`              | Ottieni informazioni sul gruppo      |
| `PATCH`  | `/api/instances/{id}/groups/{groupId}`              | Aggiorna nome/descrizione del gruppo |
| `POST`   | `/api/instances/{id}/groups/{groupId}/leave`        | Abbandona un gruppo                  |
| `GET`    | `/api/instances/{id}/groups/{groupId}/participants` | Elenca i partecipanti                |
| `POST`   | `/api/instances/{id}/groups/{groupId}/participants` | Aggiungi partecipanti                |
| `DELETE` | `/api/instances/{id}/groups/{groupId}/participants` | Rimuovi partecipanti                 |
| `GET`    | `/api/instances/{id}/groups/{groupId}/invite-code`  | Ottieni il codice di invito          |
| `POST`   | `/api/instances/{id}/groups/join`                   | Unisciti tramite codice di invito    |

***

## Gestione degli errori

| Codice di stato | Descrizione                                                                                       |
| --------------- | ------------------------------------------------------------------------------------------------- |
| `403`           | Non sei un amministratore di questo gruppo.                                                       |
| `404`           | Gruppo non trovato o l'istanza non e un membro.                                                   |
| `409`           | Il partecipante e gia nel gruppo (in caso di aggiunta) o non e nel gruppo (in caso di rimozione). |
| `422`           | Formato del partecipante non valido. Usa `{phone}@s.whatsapp.net`.                                |
