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

# Grupy

> Tworzenie, zarzadzanie i interakcja z grupami WhatsApp programowo.

# Grupy

Zarzadzaj grupami WhatsApp za pomoca Wappfy API. Mozesz tworzyc grupy, zarzadzac uczestnikami, obslugiwac linki zaproszeniowe i wiele wiecej.

Wszystkie endpointy grup sa przypisane do konkretnej instancji:

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

***

## Tworzenie grupy

Utworz nowa grupe WhatsApp z poczatkowymi uczestnikami.

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

**Odpowiedz:**

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

***

## Lista grup

Pobierz wszystkie grupy, ktorych czlonkiem jest instancja.

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

**Odpowiedz:**

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

***

## Informacje o grupie

Pobierz szczegolowe informacje o konkretnej grupie.

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

**Odpowiedz:**

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

***

## Aktualizacja grupy

Zaktualizuj nazwe lub opis grupy. Musisz byc administratorem grupy, aby wykonac ta operacje.

```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>
  Tylko administratorzy grupy moga aktualizowac nazwe i opis grupy. Jesli instancja nie jest administratorem, zostanie zwrocony blad `403`.
</Note>

***

## Opuszczenie grupy

Usun instancje z grupy.

```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>
  Po opuszczeniu grupy bedziesz potrzebowal linku zaproszeniowego lub innego administratora, aby Cie ponownie dodal.
</Warning>

***

## Uczestnicy

### Lista uczestnikow

Pobierz wszystkich uczestnikow grupy.

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

**Odpowiedz:**

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

### Dodawanie uczestnikow

Dodaj jednego lub wiecej uczestnikow do grupy. Musisz byc administratorem grupy.

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

### Usuwanie uczestnikow

Usun jednego lub wiecej uczestnikow z grupy. Musisz byc administratorem grupy.

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

***

## Kody zaproszeniowe

### Pobieranie kodu zaproszeniowego

Wygeneruj lub pobierz link zaproszeniowy grupy. Musisz byc administratorem grupy.

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

**Odpowiedz:**

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

### Dolaczanie za pomoca kodu zaproszeniowego

Dolacz do grupy za pomoca kodu zaproszeniowego.

```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>
  Przekaz tylko czesc z kodem, a nie pelny URL. Dla `https://chat.whatsapp.com/AbCdEfGhIjKlMn` przekaz `AbCdEfGhIjKlMn`.
</Note>

***

## Wysylanie wiadomosci do grup

Aby wyslac wiadomosc do grupy, uzyj standardowego endpointu [wysylania wiadomosci](/pl/guides/sending-messages) z identyfikatorem czatu grupy:

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

Identyfikatory czatow grupowych zawsze koncza sie na `@g.us`.

***

## Informacje o endpointach

| Metoda   | Endpoint                                            | Opis                                  |
| -------- | --------------------------------------------------- | ------------------------------------- |
| `POST`   | `/api/instances/{id}/groups`                        | Utworz nowa grupe                     |
| `GET`    | `/api/instances/{id}/groups`                        | Lista wszystkich grup                 |
| `GET`    | `/api/instances/{id}/groups/{groupId}`              | Informacje o grupie                   |
| `PATCH`  | `/api/instances/{id}/groups/{groupId}`              | Aktualizuj nazwe/opis grupy           |
| `POST`   | `/api/instances/{id}/groups/{groupId}/leave`        | Opusc grupe                           |
| `GET`    | `/api/instances/{id}/groups/{groupId}/participants` | Lista uczestnikow                     |
| `POST`   | `/api/instances/{id}/groups/{groupId}/participants` | Dodaj uczestnikow                     |
| `DELETE` | `/api/instances/{id}/groups/{groupId}/participants` | Usun uczestnikow                      |
| `GET`    | `/api/instances/{id}/groups/{groupId}/invite-code`  | Pobierz kod zaproszeniowy             |
| `POST`   | `/api/instances/{id}/groups/join`                   | Dolacz za pomoca kodu zaproszeniowego |

***

## Obsluga bledow

| Kod statusu | Opis                                                                                |
| ----------- | ----------------------------------------------------------------------------------- |
| `403`       | Nie jestes administratorem tej grupy.                                               |
| `404`       | Grupa nie znaleziona lub instancja nie jest czlonkiem.                              |
| `409`       | Uczestnik jest juz w grupie (przy dodawaniu) lub nie jest w grupie (przy usuwaniu). |
| `422`       | Nieprawidlowy format uczestnika. Uzyj `{phone}@s.whatsapp.net`.                     |
