## POST /api/v2/vps/{id}/backup-schedules

**Create or replace VPS backup schedule**

Create or replace a VPS scheduled backup. Read `GET /api/v2/vps/{id}/backup-schedules` first to check `limits` and `actions.canCreate`. Scheduled backups create offsite, longer-term recovery images and can take longer to create or restore than snapshots. Use snapshot schedules only for short-lived local block-on-write rollback points. For `weekly`, send `dayOfWeek` and do not send `dayOfMonth`; for `monthly`, send `dayOfMonth` and do not send `dayOfWeek`; for `daily`, send neither.

### Related Endpoints

- `GET /api/v2/vps/{id}/backup-schedules`: List VPS backup schedules
- `PATCH /api/v2/vps/{id}/backup-schedules`: Update VPS backup settings
- `DELETE /api/v2/vps/{id}/backup-schedules/{scheduleId}`: Delete VPS backup schedule

### Headers

- `Accept`: application/json
- `Authorization`: Bearer YOUR_API_KEY
- Required API scope: `write:vm`
- `Content-Type`: application/json

### Parameters

- `id` (path, string, required): Public VPS ID from `GET /api/v2/vps` `data[].id`. Do not invent this value; use the exact ID returned by the referenced API response. Example: `vps_01hxa3b4c5d6e7f8g9h0j1k2m3`

### Request Body

- `frequency` (string, required) Example: `daily`
  Allowed values: daily, weekly, monthly
- `hour` (integer, required) [min: 0, max: 23] Example: `2`
- `dayOfWeek` (integer, optional) [min: 0, max: 6]: Required only when `frequency` is `weekly`; 0 is Sunday. Example: `1`
- `dayOfMonth` (integer, optional) [min: 1, max: 31]: Required only when `frequency` is `monthly`. Example: `15`
- `retentionCount` (integer, required) [min: 1] Example: `3`
- `enabled` (boolean, required) Example: `true`
- `name` (string, optional) Example: `Nightly backup`

### Request Examples

#### Daily backup schedule

```bash
curl -X POST "https://cloud.hostup.se/api/v2/vps/vps_01hxa3b4c5d6e7f8g9h0j1k2m3/backup-schedules" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "frequency": "daily",
    "hour": 2,
    "retentionCount": 3,
    "enabled": true,
    "name": "Nightly backup"
  }'
```

```json
{
  "frequency": "daily",
  "hour": 2,
  "retentionCount": 3,
  "enabled": true,
  "name": "Nightly backup"
}
```

### Response Schema

- `id` (string, required) Example: `bks_01hxa3b4c5d6e7f8g9h0j1k2m3`
- `name` (string, required) Example: `Nightly backup`
- `frequency` (string, required) Example: `daily`
  Allowed values: daily, weekly, monthly
- `time` (string,null, required) Example: `02:00`
- `daySpecifier` (string,null, required) Example: `null`
- `retentionCount` (integer, required) Example: `3`
- `enabled` (boolean, required) Example: `true`
- `lastRun` (string,null, required) Example: `2026-04-27T02:00:00.000Z`
- `nextRun` (string,null, required) Example: `2026-04-28T02:00:00.000Z`
- `status` (string,null, required) Example: `completed`
  Allowed values: completed, running, queued, failed, cancelled, unknown, 

### Responses

#### 201 - Backup schedule saved.
```json
{
  "id": "bks_01hxa3b4c5d6e7f8g9h0j1k2m3",
  "name": "Nightly backup",
  "frequency": "daily",
  "time": "02:00",
  "daySpecifier": null,
  "retentionCount": 3,
  "enabled": true,
  "lastRun": null,
  "nextRun": "2026-04-28T02:00:00.000Z",
  "status": null
}
```

#### 400 - Invalid request. The response body is an RFC 7807 Problem Details document.
```json
{
  "type": "https://developer.hostup.se/errors/invalid_request",
  "title": "Invalid request",
  "status": 400,
  "detail": "The request body failed validation.",
  "code": "invalid_request",
  "instance": "/api/v2/resource",
  "requestId": "req_01hxa3b4c5d6e7f8g9h0j1k2m3",
  "timestamp": "2026-04-27T12:34:56.000Z",
  "errors": [
    {
      "pointer": "/items/0/domainName",
      "detail": "`domainName` is required.",
      "code": "invalid_request"
    }
  ]
}
```

#### 401 - Unauthorized. Authentication is required.
```json
{
  "type": "https://developer.hostup.se/errors/unauthorized",
  "title": "Unauthorized",
  "status": 401,
  "detail": "Authentication is required.",
  "code": "unauthorized",
  "instance": "/api/v2/resource",
  "requestId": "req_01hxa3b4c5d6e7f8g9h0j1k2m3",
  "timestamp": "2026-04-27T12:34:56.000Z"
}
```

#### 403 - Forbidden. The caller lacks a required scope or does not own the resource.
```json
{
  "type": "https://developer.hostup.se/errors/forbidden",
  "title": "Forbidden",
  "status": 403,
  "detail": "The caller lacks a required scope or does not own the resource.",
  "code": "forbidden",
  "instance": "/api/v2/resource",
  "requestId": "req_01hxa3b4c5d6e7f8g9h0j1k2m3",
  "timestamp": "2026-04-27T12:34:56.000Z"
}
```

#### 404 - Not found. The resource does not exist or is not owned by the caller.
```json
{
  "type": "https://developer.hostup.se/errors/not_found",
  "title": "Not found",
  "status": 404,
  "detail": "The requested resource could not be found.",
  "code": "not_found",
  "instance": "/api/v2/resource",
  "requestId": "req_01hxa3b4c5d6e7f8g9h0j1k2m3",
  "timestamp": "2026-04-27T12:34:56.000Z"
}
```

#### 429 - Rate limited. Retry after the limit resets. 429 responses include `Retry-After` seconds plus `X-RateLimit-*` headers.
```json
{
  "type": "https://developer.hostup.se/errors/rate_limit_exceeded",
  "title": "Too many requests",
  "status": 429,
  "detail": "Too many requests. Retry after the limit resets.",
  "code": "rate_limit_exceeded",
  "instance": "/api/v2/resource",
  "requestId": "req_01hxa3b4c5d6e7f8g9h0j1k2m3",
  "timestamp": "2026-04-27T12:34:56.000Z"
}
```

#### 500 - Internal error. Retry later or contact support if the issue persists.
```json
{
  "type": "https://developer.hostup.se/errors/internal_error",
  "title": "Internal server error",
  "status": 500,
  "detail": "An unexpected error occurred. Retry later or contact support if the issue persists.",
  "code": "internal_error",
  "instance": "/api/v2/resource",
  "requestId": "req_01hxa3b4c5d6e7f8g9h0j1k2m3",
  "timestamp": "2026-04-27T12:34:56.000Z"
}
```
