> ## 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.

# Grupos

> Crea, gestiona e interactua con grupos de WhatsApp de forma programatica.

# Grupos

Gestiona grupos de WhatsApp a traves de la API de Wappfy. Puedes crear grupos, administrar participantes, manejar enlaces de invitacion y mas.

Todos los endpoints de grupos estan asociados a una instancia especifica:

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

***

## Crear un grupo

Crea un nuevo grupo de WhatsApp con participantes iniciales.

<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>

**Respuesta:**

```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
      }
    ]
  }
}
```

***

## Listar grupos

Recupera todos los grupos de los que la instancia es miembro.

<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>

**Respuesta:**

```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
    }
  ]
}
```

***

## Obtener informacion del grupo

Obtiene informacion detallada sobre un grupo especifico.

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

**Respuesta:**

```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
      }
    ]
  }
}
```

***

## Actualizar un grupo

Actualiza el nombre o la descripcion del grupo. Debes ser administrador del grupo para realizar esta accion.

```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 los administradores del grupo pueden actualizar el nombre y la descripcion. Si la instancia no es administrador, se devolvera un error `403`.
</Note>

***

## Salir de un grupo

Elimina la instancia de un grupo.

```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>
  Despues de salir de un grupo, necesitaras un enlace de invitacion o que otro administrador te agregue nuevamente.
</Warning>

***

## Participantes

### Listar participantes

Obtiene todos los participantes de un grupo.

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

**Respuesta:**

```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
    }
  ]
}
```

### Agregar participantes

Agrega uno o mas participantes a un grupo. Debes ser administrador del grupo.

<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>

### Eliminar participantes

Elimina uno o mas participantes de un grupo. Debes ser administrador del grupo.

```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"
    ]
  }'
```

***

## Codigos de invitacion

### Obtener codigo de invitacion

Genera o recupera el enlace de invitacion del grupo. Debes ser administrador del grupo.

```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"
```

**Respuesta:**

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

### Unirse mediante codigo de invitacion

Unete a un grupo usando un codigo de invitacion.

```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>
  Pasa solo la parte del codigo, no la URL completa. Para `https://chat.whatsapp.com/AbCdEfGhIjKlMn`, pasa `AbCdEfGhIjKlMn`.
</Note>

***

## Enviar mensajes a grupos

Para enviar un mensaje a un grupo, usa el endpoint estandar de [envio de mensajes](/es/guides/sending-messages) con el chat ID del grupo:

```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!"
  }'
```

Los chat ID de grupo siempre terminan en `@g.us`.

***

## Referencia de endpoints

| Metodo   | Endpoint                                            | Descripcion                             |
| -------- | --------------------------------------------------- | --------------------------------------- |
| `POST`   | `/api/instances/{id}/groups`                        | Crear un nuevo grupo                    |
| `GET`    | `/api/instances/{id}/groups`                        | Listar todos los grupos                 |
| `GET`    | `/api/instances/{id}/groups/{groupId}`              | Obtener informacion del grupo           |
| `PATCH`  | `/api/instances/{id}/groups/{groupId}`              | Actualizar nombre/descripcion del grupo |
| `POST`   | `/api/instances/{id}/groups/{groupId}/leave`        | Salir de un grupo                       |
| `GET`    | `/api/instances/{id}/groups/{groupId}/participants` | Listar participantes                    |
| `POST`   | `/api/instances/{id}/groups/{groupId}/participants` | Agregar participantes                   |
| `DELETE` | `/api/instances/{id}/groups/{groupId}/participants` | Eliminar participantes                  |
| `GET`    | `/api/instances/{id}/groups/{groupId}/invite-code`  | Obtener codigo de invitacion            |
| `POST`   | `/api/instances/{id}/groups/join`                   | Unirse mediante codigo de invitacion    |

***

## Manejo de errores

| Codigo de estado | Descripcion                                                                           |
| ---------------- | ------------------------------------------------------------------------------------- |
| `403`            | No eres administrador de este grupo.                                                  |
| `404`            | Grupo no encontrado o la instancia no es miembro.                                     |
| `409`            | El participante ya esta en el grupo (al agregar) o no esta en el grupo (al eliminar). |
| `422`            | Formato de participante invalido. Usa `{phone}@s.whatsapp.net`.                       |
