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

# Link groups

> Link existing groups to a community as subgroups

**Auth:** `TokenAccount` or `TokenInstance` • **Rate-limit:** `Global` (100/min) • **Idempotent:** no

## Description

Links one or more existing groups to a community. Each link has an **internal 1s delay** to avoid throttling from the WhatsApp server. Individual failures do not abort the operation, they go to the `failed` array.

## Examples

### Link 2 groups

Bulk-attaches 2 existing groups to the community `120363406289005073@g.us` in a single call. The service applies an internal 1s delay between links to avoid throttling.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://ryzeapi.cloud/api/community/link/$Instance_Name" \
    -H "token: $Token_Instance" \
    -H "Content-Type: application/json" \
    -d '{
      "communityJid": "120363406289005073@g.us",
      "groupJid": [
        "120363406289005074@g.us",
        "120363406289005075@g.us"
      ]
    }'
  ```

  ```javascript JavaScript theme={null}
  await fetch(`https://ryzeapi.cloud/api/community/link/${process.env.Instance_Name}`, {
    method: "POST",
    headers: {
      "token":        process.env.Token_Instance,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      communityJid: "120363406289005073@g.us",
      groupJid: [
        "120363406289005074@g.us",
        "120363406289005075@g.us"
      ]
    })
  });
  ```

  ```python Python theme={null}
  import os, requests

  requests.post(
      f"https://ryzeapi.cloud/api/community/link/{os.environ['Instance_Name']}",
      headers={
          "token":        os.environ["Token_Instance"],
          "Content-Type": "application/json"
      },
      json={
          "communityJid": "120363406289005073@g.us",
          "groupJid": [
              "120363406289005074@g.us",
              "120363406289005075@g.us"
          ]
      }
  )
  ```

  ```go Go theme={null}
  package main

  import (
      "net/http"
      "os"
      "strings"
  )

  func main() {
      body := strings.NewReader(`{
          "communityJid": "120363406289005073@g.us",
          "groupJid": [
              "120363406289005074@g.us",
              "120363406289005075@g.us"
          ]
      }`)
      req, _ := http.NewRequest("POST", "https://ryzeapi.cloud/api/community/link/"+os.Getenv("Instance_Name"), body)
      req.Header.Set("token", os.Getenv("Token_Instance"))
      req.Header.Set("Content-Type", "application/json")
      http.DefaultClient.Do(req)
  }
  ```
</CodeGroup>

### Link 1 group

Links a single group to the community. The `groupJid` array accepts 1 or more items, useful when you want to add subgroups one by one.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://ryzeapi.cloud/api/community/link/$Instance_Name" \
    -H "token: $Token_Instance" \
    -H "Content-Type: application/json" \
    -d '{
      "communityJid": "120363406289005073@g.us",
      "groupJid": ["120363406289005074@g.us"]
    }'
  ```

  ```javascript JavaScript theme={null}
  await fetch(`https://ryzeapi.cloud/api/community/link/${process.env.Instance_Name}`, {
    method: "POST",
    headers: {
      "token":        process.env.Token_Instance,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      communityJid: "120363406289005073@g.us",
      groupJid: ["120363406289005074@g.us"]
    })
  });
  ```

  ```python Python theme={null}
  import os, requests

  requests.post(
      f"https://ryzeapi.cloud/api/community/link/{os.environ['Instance_Name']}",
      headers={
          "token":        os.environ["Token_Instance"],
          "Content-Type": "application/json"
      },
      json={
          "communityJid": "120363406289005073@g.us",
          "groupJid":     ["120363406289005074@g.us"]
      }
  )
  ```

  ```go Go theme={null}
  package main

  import (
      "net/http"
      "os"
      "strings"
  )

  func main() {
      body := strings.NewReader(`{
          "communityJid": "120363406289005073@g.us",
          "groupJid": ["120363406289005074@g.us"]
      }`)
      req, _ := http.NewRequest("POST", "https://ryzeapi.cloud/api/community/link/"+os.Getenv("Instance_Name"), body)
      req.Header.Set("token", os.Getenv("Token_Instance"))
      req.Header.Set("Content-Type", "application/json")
      http.DefaultClient.Do(req)
  }
  ```
</CodeGroup>

## Success response

Returns the count in `message` (format `"Linked N of M groups to community"`), the `linked` array with the JIDs successfully linked, and `failed` with the ones that were not processed (invalid JID, group already linked to another community, or bot lacking permission). `success` is `true` when at least one group was linked.

```json 200 OK theme={null}
{
  "success": true,
  "message": "Linked 2 of 2 groups to community",
  "linked": [
    "120363406289005074@g.us",
    "120363406289005075@g.us"
  ],
  "failed": []
}
```

<Warning>
  Partial success and total failure both return **HTTP 200**. Always check `success` + `failed[]` on the client to detect per-group errors.
</Warning>

## Path parameters

<ParamField path="instance" type="string" required>
  Instance name.
</ParamField>

## Headers

<ParamField header="token" type="string" required>
  `TokenAccount` or `TokenInstance`.
</ParamField>

<ParamField header="Content-Type" type="string" required>
  `application/json`
</ParamField>

## Request body

<ParamField body="communityJid" type="string" required>
  Community `@g.us` JID.
</ParamField>

<ParamField body="groupJid" type="string[]" required>
  Array of `@g.us` JIDs of the groups to link. At least **1** item.
</ParamField>

## Notes

<Note>
  * A group already linked to **another community** lands in `failed[]`, unlink it first via [`/unlink`](/en/api/communities/unlink).
  * Limit of **50 subgroups** per community. Extras fail silently.
  * The **Announcements group** already belongs to the community since creation and cannot be linked.
  * The bot must be admin of both the community and the group being linked.
</Note>

## Errors

| HTTP | Message                                 |
| ---- | --------------------------------------- |
| 400  | `community jid is required`             |
| 400  | `group jid is required`                 |
| 400  | `Instance is not connected to WhatsApp` |
| 500  | `error parse community jid: <reason>`   |

Envelope:

```json theme={null}
{
  "success": false,
  "error": { "message": "community jid is required" }
}
```

## Next

<CardGroup cols={2}>
  <Card title="Unlink groups" icon="link-slash" href="/en/api/communities/unlink">
    Remove groups from the community.
  </Card>

  <Card title="List subgroups" icon="list" href="/en/api/communities/list-subgroups">
    Confirm the linked subgroups.
  </Card>
</CardGroup>
