# Extend a User’s Subscription Bot Memberships

> Move a user’s Telegram or Discord subscription bot memberships to a future end date through the project API.

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

Move all eligible memberships belonging to the specified user within this project forward to a target date. This can affect memberships for multiple plans.

Only `extend` is accepted in the body. Sending `membership_ids` or `all_memberships` returns `422`. To select a particular membership or a batch by ID, use [selected membership extension](https://docs.botsubscription.com/api/memberships/extend/).

Memberships that already end later, lifetime memberships, and expired memberships whose plan is full are skipped. More than 10,000 memberships for this user returns `409` without changes. This sets an end date, not an additional duration; sending the same date again does not extend twice.

Use the [project membership list](https://docs.botsubscription.com/api/memberships/list/) to inspect the resulting memberships.

<ApiEndpoint method="PATCH" endpoint="/v2/projects/{project_id}/memberships/{user_id}/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." />
  <ApiParameter name="user_id" type="string" required description="The user whose eligible memberships to extend across all plans in this project." />
</ApiSection>

<ApiSection title="Request Body">
  <ApiParameter name="extend" type="string | number" required description="Future absolute 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." />
</ApiSection>

<ApiSamplePane>

<ApiRequestSample title="Request">

```bash
curl -X PATCH "https://api.botsubscription.com/v2/projects/YOUR_PROJECT_ID/memberships/123456789012345678/extend" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "extend": "2027-12-31T23:59:59.000Z"
  }'
```

```javascript
const project_id = 'YOUR_PROJECT_ID';
const user_id = '123456789012345678';

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

const response = await fetch(`https://api.botsubscription.com/v2/projects/${project_id}/memberships/${user_id}/extend`, {
  method: 'PATCH',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ extend })
});
const data = await response.json();
```

```python
import requests

project_id = 'YOUR_PROJECT_ID'
user_id = '123456789012345678'

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

response = requests.patch(
    f'https://api.botsubscription.com/v2/projects/{project_id}/memberships/{user_id}/extend',
    headers={'Authorization': 'Bearer YOUR_API_KEY'},
    json={'extend': extend}
)
data = response.json()
```

```php
$project_id = 'YOUR_PROJECT_ID';
$user_id = '123456789012345678';

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

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.botsubscription.com/v2/projects/{$project_id}/memberships/{$user_id}/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
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
```

</ApiRequestSample>

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

```json
{
  "ok": true,
  "request_id": "11111111-1111-1111-1111-111111111111",
  "method": "PATCH",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/memberships/123456789012345678/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/123456789012345678/extend",
  "code": 422,
  "error": {
    "error_code": "VALIDATION_ERROR",
    "message": "extend must be a future timestamp"
  }
}
```

  </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/123456789012345678/extend",
  "code": 401,
  "error": {
    "message": "Invalid or expired authentication token.",
    "error_code": "UNAUTHORIZED"
  }
}
```

  </ApiResponse>
</ApiResponseTabs>

</ApiSamplePane>
