# Join communities and run the ones you manage

> Join and leave communities, accept invites, and for communities you run change the settings, invite members and answer join requests with the API.

Source: https://docs.urnextdoor.com/guides/manage-communities/

[Creating a community](https://docs.urnextdoor.com/guides/create-community.md) is its own guide. This one is everything after.

**Scopes:** `network` for membership, `edit` for settings · **Quotas:** joining and inviting use `connect` (one unit per person invited); settings use `edit`

## Membership

| What | Endpoint |
| --- | --- |
| Join a public community, or ask to join one that asks | `POST /api/v1/communities/{slug}/join` |
| Leave, cancel your request, or turn down an invite | `POST /api/v1/communities/{slug}/leave` |
| Accept an invite | `POST /api/v1/communities/{slug}/invite/accept` |
| Decline an invite | `POST /api/v1/communities/{slug}/invite/decline` |

A private community is by invite only. The answer's `membership` says where you stand. The creator cannot leave their own community.

## Communities you run

Admins and the creator can:

| What | Endpoint |
| --- | --- |
| Read the settings | `GET /api/v1/communities/{slug}/settings` |
| Change the settings | `PUT /api/v1/communities/{slug}` |
| Invite up to 10 members | `POST /api/v1/communities/{slug}/invites` with `{"usernames": [...]}` |
| Accept or decline a request to join | `POST /api/v1/communities/{slug}/requests/accept` or `/decline` with `{"username": "..."}` |

A settings change sends only what changes; the name, description, icon, banner and visibility you do not send are kept. An `icon_url` or `banner_url` that links to an image elsewhere is imported. Changing roles and removing members stay on the website.

**cURL**

```bash
curl -X PUT "https://urnextdoor.com/api/v1/communities/rooftop-growers" \
  -H "Authorization: Bearer $UND_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "description": "<p>Gardens on roofs across Pune.</p>"
}'
```

**JavaScript**

```js
const res = await fetch("https://urnextdoor.com/api/v1/communities/rooftop-growers", {
  method: "PUT",
  headers: {
    Authorization: `Bearer ${process.env.UND_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    description: "<p>Gardens on roofs across Pune.</p>",
  }),
});
console.log(res.status, await res.json());
```

**Python**

```python
import os

import requests

api_key = os.environ["UND_API_KEY"]

response = requests.put(
    "https://urnextdoor.com/api/v1/communities/rooftop-growers",
    headers={
        "Authorization": f"Bearer {api_key}",
    },
    json={
        "description": "<p>Gardens on roofs across Pune.</p>",
    },
    timeout=30,
)
print(response.status_code, response.json())
```

**PHP**

```php
<?php
$apiKey = getenv('UND_API_KEY');

$payload = [
    'description' => '<p>Gardens on roofs across Pune.</p>',
];

$ch = curl_init('https://urnextdoor.com/api/v1/communities/rooftop-growers');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'PUT',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . $apiKey,
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => json_encode($payload),
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);

echo $status, PHP_EOL, $body, PHP_EOL;
```

## Next steps

- [Create a community](https://docs.urnextdoor.com/guides/create-community.md).
- [Follow, connect and block](https://docs.urnextdoor.com/guides/network.md).
- [API reference: Communities](https://docs.urnextdoor.com/reference/communities.md).
