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

# Gérer les membres

> Ajoutez, retirez, promouvez ou rétrograder des membres dans un groupe WhatsApp.

## Endpoints

### Option 1: GroupJid dans le body

```http theme={null}
POST https://api.wachap.com/v1/whatsapp/groups/members
```

### Option 2: GroupJid dans l'URL (rétrocompatibilité)

```http theme={null}
POST https://api.wachap.com/v1/whatsapp/groups/:groupJid/members
```

## Headers

| Paramètre     | Type   | Requis | Description                                                  |
| :------------ | :----- | :----- | :----------------------------------------------------------- |
| Authorization | string | Oui    | Bearer token avec votre Secret Key (format: `Bearer sk_...`) |

## Body Parameters (Option 1)

| Paramètre    | Type   | Requis | Description                                                 |
| :----------- | :----- | :----- | :---------------------------------------------------------- |
| accountId    | string | Oui    | L'identifiant du compte WhatsApp                            |
| groupJid     | string | Oui    | L'identifiant du groupe (format: `120363123456789012@g.us`) |
| action       | string | Oui    | Action à effectuer: `add`, `remove`, `promote`, `demote`    |
| participants | array  | Oui    | Liste des numéros de téléphone au format international      |

## Body Parameters (Option 2)

| Paramètre    | Type   | Requis | Description                                              |
| :----------- | :----- | :----- | :------------------------------------------------------- |
| accountId    | string | Oui    | L'identifiant du compte WhatsApp                         |
| action       | string | Oui    | Action à effectuer: `add`, `remove`, `promote`, `demote` |
| participants | array  | Oui    | Liste des numéros de téléphone au format international   |

## Actions disponibles

| Action    | Description                                        |
| :-------- | :------------------------------------------------- |
| `add`     | Ajouter des membres au groupe                      |
| `remove`  | Retirer des membres du groupe                      |
| `promote` | Promouvoir des membres en tant qu'administrateurs  |
| `demote`  | Rétrograder des administrateurs en membres normaux |

## Exemples de requêtes

### Ajouter des membres (Option 1)

```bash theme={null}
curl -X POST https://api.wachap.com/v1/whatsapp/groups/members \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer token" \
  -d '{
    "accountId": "a1233b-a1233b-a1233b-a1233b-a1233bcdjdg9878",
    "groupJid": "120363123456789012@g.us",
    "action": "add",
    "participants": ["+33612345678", "+2290112345678"]
  }'
```

### Retirer des membres (Option 2)

```bash theme={null}
curl -X POST https://api.wachap.com/v1/whatsapp/groups/120363123456789012@g.us/members \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer token" \
  -d '{
    "accountId": "a1233b-a1233b-a1233b-a1233b-a1233bcdjdg9878",
    "action": "remove",
    "participants": ["+33698765432"]
  }'
```

### Promouvoir en administrateur

```bash theme={null}
curl -X POST https://api.wachap.com/v1/whatsapp/groups/members \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer token" \
  -d '{
    "accountId": "a1233b-a1233b-a1233b-a1233b-a1233bcdjdg9878",
    "groupJid": "120363123456789012@g.us",
    "action": "promote",
    "participants": ["+33612345678"]
  }'
```

### Rétrograder un administrateur

```bash theme={null}
curl -X POST https://api.wachap.com/v1/whatsapp/groups/members \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer token" \
  -d '{
    "accountId": "a1233b-a1233b-a1233b-a1233b-a1233bcdjdg9878",
    "groupJid": "120363123456789012@g.us",
    "action": "demote",
    "participants": ["+33612345678"]
  }'
```

## Exemple de réponse

```json theme={null}
{
  "success": true,
  "message": "Action effectuée avec succès",
  "action": "add",
  "groupJid": "120363123456789012@g.us",
  "participants": [
    "33612345678@s.whatsapp.net",
    "2290112345678@s.whatsapp.net"
  ],
  "results": [
    {
      "jid": "33612345678@s.whatsapp.net",
      "status": "success"
    },
    {
      "jid": "2290112345678@s.whatsapp.net",
      "status": "success"
    }
  ]
}
```

## Notes

* Vous devez être administrateur du groupe pour effectuer ces actions
* Pour `promote` et `demote`, les participants doivent déjà être membres du groupe
* Pour `add`, les participants ne doivent pas déjà être dans le groupe
* Pour `remove`, vous ne pouvez pas vous retirer vous-même

## Codes d'erreur

| Code | Description                                                              |
| :--- | :----------------------------------------------------------------------- |
| 400  | `MISSING_ACCOUNT_ID` - accountId manquant                                |
| 400  | `MISSING_GROUP_JID` - groupJid manquant                                  |
| 400  | `MISSING_ACTION` - action manquante                                      |
| 400  | `INVALID_ACTION` - action invalide                                       |
| 400  | `MISSING_PARTICIPANTS` - participants manquant ou vide                   |
| 401  | `INVALID_SECRET_KEY` - Clé secrète invalide                              |
| 403  | `NOT_ADMIN` - Vous n'êtes pas administrateur du groupe                   |
| 403  | `NOT_CREATOR` - Seul le créateur peut promouvoir/rétrograder (selon cas) |
| 404  | `ACCOUNT_NOT_FOUND` - Compte WhatsApp non trouvé                         |
| 404  | `GROUP_NOT_FOUND` - Groupe non trouvé                                    |


## OpenAPI

````yaml POST /whatsapp/groups/members
openapi: 3.0.3
info:
  title: WaChap API
  version: 2.0.0
servers:
  - url: https://api.wachap.com/v1
    description: WaChap API server
security:
  - BearerAuth: []
tags:
  - name: Instances
    description: Créer et gérer des instances WhatsApp
  - name: Webhook
    description: Configuration des webhooks de réception
  - name: Messages
    description: Envoyer des messages WhatsApp
  - name: Comptes
    description: Gérer vos comptes WhatsApp connectés
  - name: SMS
    description: Service SMS de WaChap (V4) via FCM
  - name: Étiquettes WhatsApp
    description: Créer et associer des étiquettes aux conversations WhatsApp
paths:
  /whatsapp/groups/members:
    post:
      tags:
        - Groupes WhatsApp
      summary: Gérer les membres
      description: >-
        Ajoutez, retirez, promouvez ou rétrograder des membres dans un groupe
        WhatsApp.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                accountId:
                  type: string
                groupJid:
                  type: string
                action:
                  type: string
                  enum:
                    - add
                    - remove
                    - promote
                    - demote
                  description: Action à effectuer
                participants:
                  type: array
                  items:
                    type: string
                  description: Liste des numéros de téléphone (format international)
      responses:
        '200':
          description: OK
components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````