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

# Grup

> Buat, kelola, dan berinteraksi dengan grup WhatsApp secara programatis.

# Grup

Kelola grup WhatsApp melalui Wappfy API. Anda dapat membuat grup, mengelola peserta, menangani link undangan, dan lainnya.

Semua endpoint grup terikat pada instance tertentu:

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

***

## Membuat Grup

Buat grup WhatsApp baru dengan peserta awal.

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

**Respons:**

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

***

## Melihat Daftar Grup

Ambil semua grup yang diikuti instance.

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

**Respons:**

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

***

## Mendapatkan Info Grup

Ambil informasi detail tentang grup tertentu.

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

**Respons:**

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

***

## Memperbarui Grup

Perbarui nama atau deskripsi grup. Anda harus menjadi admin grup untuk melakukan tindakan ini.

```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>
  Hanya admin grup yang dapat memperbarui nama dan deskripsi grup. Jika instance bukan admin, ini akan mengembalikan error `403`.
</Note>

***

## Keluar dari Grup

Keluarkan instance dari grup.

```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>
  Setelah keluar dari grup, Anda memerlukan link undangan atau admin lain untuk menambahkan Anda kembali.
</Warning>

***

## Peserta

### Melihat Daftar Peserta

Dapatkan semua peserta dari sebuah grup.

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

**Respons:**

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

### Menambahkan Peserta

Tambahkan satu atau beberapa peserta ke grup. Anda harus menjadi admin grup.

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

### Menghapus Peserta

Hapus satu atau beberapa peserta dari grup. Anda harus menjadi admin grup.

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

***

## Kode Undangan

### Mendapatkan Kode Undangan

Hasilkan atau ambil link undangan grup. Anda harus menjadi admin grup.

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

**Respons:**

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

### Bergabung melalui Kode Undangan

Bergabung ke grup menggunakan kode undangan.

```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>
  Kirimkan hanya bagian kode, bukan URL lengkap. Untuk `https://chat.whatsapp.com/AbCdEfGhIjKlMn`, kirimkan `AbCdEfGhIjKlMn`.
</Note>

***

## Mengirim Pesan ke Grup

Untuk mengirim pesan ke grup, gunakan endpoint standar [kirim pesan](/id/guides/sending-messages) dengan chat ID grup:

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

Chat ID grup selalu diakhiri dengan `@g.us`.

***

## Referensi Endpoint

| Method   | Endpoint                                            | Deskripsi                       |
| -------- | --------------------------------------------------- | ------------------------------- |
| `POST`   | `/api/instances/{id}/groups`                        | Membuat grup baru               |
| `GET`    | `/api/instances/{id}/groups`                        | Melihat daftar semua grup       |
| `GET`    | `/api/instances/{id}/groups/{groupId}`              | Mendapatkan info grup           |
| `PATCH`  | `/api/instances/{id}/groups/{groupId}`              | Memperbarui nama/deskripsi grup |
| `POST`   | `/api/instances/{id}/groups/{groupId}/leave`        | Keluar dari grup                |
| `GET`    | `/api/instances/{id}/groups/{groupId}/participants` | Melihat daftar peserta          |
| `POST`   | `/api/instances/{id}/groups/{groupId}/participants` | Menambahkan peserta             |
| `DELETE` | `/api/instances/{id}/groups/{groupId}/participants` | Menghapus peserta               |
| `GET`    | `/api/instances/{id}/groups/{groupId}/invite-code`  | Mendapatkan kode undangan       |
| `POST`   | `/api/instances/{id}/groups/join`                   | Bergabung melalui kode undangan |

***

## Penanganan Error

| Kode Status | Deskripsi                                                                                   |
| ----------- | ------------------------------------------------------------------------------------------- |
| `403`       | Anda bukan admin grup ini.                                                                  |
| `404`       | Grup tidak ditemukan atau instance bukan anggota.                                           |
| `409`       | Peserta sudah ada dalam grup (saat menambahkan) atau tidak ada dalam grup (saat menghapus). |
| `422`       | Format peserta tidak valid. Gunakan `{phone}@s.whatsapp.net`.                               |
