# Extend Subscription Bot Memberships

> Extend selected memberships by ID or update your entire Telegram and Discord subscription bot project through the API.

Source: https://docs.botsubscription.com/api/memberships/extend/

Set a future end date for one membership, a selected batch, or all memberships in your Telegram or Discord subscription bot project. `extend` is a target date, not a duration.

Restricted keys can extend selected `membership_ids`. Whole-project updates with `all_memberships: true` require an unrestricted project API key.

**Choose exactly one selector:** `membership_ids` or `all_memberships: true`. Sending neither selector, or both, returns `422`.

<ApiEndpoint method="PATCH" endpoint="/v2/projects/{project_id}/memberships/extend" />

<ApiAuthorization type="Bearer API Key" />

**API key scope:** `memberships:update` (required for restricted keys).

<ApiSection title="Path Parameters">
  <ApiParameter name="project_id" type="string" required description="The unique identifier of the project." />
</ApiSection>

<ApiSection title="Request Body">
  <ApiParameter name="extend" type="string | number" required description="Future target expiry in UTC ISO format YYYY-MM-DDTHH:mm:ss.sssZ, for example 2030-01-01T00:00:00.000Z. Also accepts 13-digit Unix milliseconds for compatibility." />
  <ApiParameter name="membership_ids" type="string[]" description="One to 100 distinct membership UUIDs. Use a one-item array to extend a particular membership." />
  <ApiParameter name="all_memberships" type="boolean" description="Must be true when selecting the whole project. Cannot be combined with membership_ids." />
</ApiSection>

## Selection and subscription limits

For `membership_ids`, every membership must exist in this project, have no pending termination, and end on or before the target. Reactivating expired access must fit the plan's subscriber limit. A failure returns `404` or `409` without changing the selection.

For `all_memberships: true`, later end dates, lifetime memberships, and expired memberships whose plans are full are skipped. More than 10,000 memberships returns `409` without changes. The response message reports skipped memberships.

End dates never move earlier, and lifetime memberships are never given an expiration. Sending the same target again succeeds without extending access twice. Find IDs through the [membership list API](https://docs.botsubscription.com/api/memberships/list/). To update a user's memberships together, use the [user membership extension route](https://docs.botsubscription.com/api/memberships/extend-user/).

To extend a membership granted through [Redeem for Member](https://docs.botsubscription.com/api/access-tokens/redeem/), put its returned `membership_id` in a one-item `membership_ids` array.

Whole-project body:

```json
{ "extend": "2027-12-31T23:59:59.000Z", "all_memberships": true }
```

<ApiSamplePane>

<ApiRequestSample title="Request">

```bash
curl -X PATCH "https://api.botsubscription.com/v2/projects/YOUR_PROJECT_ID/memberships/extend" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "membership_ids": ["6f9619ff-8b86-4011-b42d-00cf4fc964ff"],
    "extend": "2027-12-31T23:59:59.000Z"
  }'
```

```javascript
const project_id = 'YOUR_PROJECT_ID';

const extend = '2027-12-31T23:59:59.000Z';

const response = await fetch(`https://api.botsubscription.com/v2/projects/${project_id}/memberships/extend`, {
  method: 'PATCH',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ extend, membership_ids: ['6f9619ff-8b86-4011-b42d-00cf4fc964ff'] })
});
const data = await response.json();
```

```python
import requests

project_id = 'YOUR_PROJECT_ID'

extend = '2027-12-31T23:59:59.000Z'

response = requests.patch(
    f'https://api.botsubscription.com/v2/projects/{project_id}/memberships/extend',
    headers={'Authorization': 'Bearer YOUR_API_KEY'},
    json={'extend': extend, 'membership_ids': ['6f9619ff-8b86-4011-b42d-00cf4fc964ff']}
)
data = response.json()
```

```php
$project_id = 'YOUR_PROJECT_ID';

$extend = '2027-12-31T23:59:59.000Z';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.botsubscription.com/v2/projects/{$project_id}/memberships/extend");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer YOUR_API_KEY',
    'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
    'extend' => $extend,
    'membership_ids' => ['6f9619ff-8b86-4011-b42d-00cf4fc964ff']
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
```

</ApiRequestSample>

<ApiResponseTabs>
  <ApiResponse status={200} description="Memberships extended">

```json
{
  "ok": true,
  "request_id": "11111111-1111-1111-1111-111111111111",
  "method": "PATCH",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/memberships/extend",
  "code": 200,
  "total": 1,
  "message": "Membership end dates set successfully",
  "data": {
    "new_end_date": "2027-12-31T23:59:59.000Z"
  }
}
```

  </ApiResponse>
  <ApiResponse status={422} description="Past timestamp">

```json
{
  "ok": false,
  "request_id": "11111111-1111-1111-1111-111111111111",
  "method": "PATCH",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/memberships/extend",
  "code": 422,
  "error": {
    "error_code": "VALIDATION_ERROR",
    "message": "extend must be a future timestamp"
  }
}
```

  </ApiResponse>
  <ApiResponse status={422} description="Membership selection is required">

```json
{
  "ok": false,
  "request_id": "44444444-4444-4444-8444-444444444444",
  "method": "PATCH",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/memberships/extend",
  "code": 422,
  "errors": [
    {
      "message": "body: Provide exactly one of membership_ids or all_memberships: true",
      "error_code": "VALIDATION_ERROR"
    }
  ]
}
```

  </ApiResponse>
  <ApiResponse status={401} description="Invalid or expired API key">

```json
{
  "ok": false,
  "request_id": "44444444-4444-4444-8444-444444444444",
  "method": "PATCH",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/memberships/extend",
  "code": 401,
  "error": {
    "message": "Invalid or expired authentication token.",
    "error_code": "UNAUTHORIZED"
  }
}
```

  </ApiResponse>
</ApiResponseTabs>

</ApiSamplePane>
