## POST /api/v2/domains/bulk/autorenew

**Queue a bulk auto-renew toggle**

Enable or disable auto-renew for multiple domains. Send public `dom_...` IDs in `domainIds` and the target boolean in `enabled`. Normal successful toggles queue a bulk job and return `202`. Disabling auto-renew has a confirmation branch: if pending renewal orders exist, the first request returns `200` with `pendingOrdersFound: true` and `pendingOrders[]`; show those orders to the user, then re-submit the same request with `confirmCancelPending: true` to cancel them and continue. Cancelling pending renewal orders requires `write:billing`, and contact sub-accounts also need order-placement permission. Invalid or foreign domain IDs reject the whole batch with Problem Details.

### Related Endpoints

- `POST /api/v2/domains/bulk/dns`: Queue a bulk DNS record operation
- `POST /api/v2/domains/bulk/renew`: Queue bulk domain renewals
- `POST /api/v2/domains/bulk/contacts`: Queue a bulk domain contact update

### Headers

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

### Request Body

- `domainIds` (array<string>, required) Example: `["dom_01hxa3b4c5d6e7f8g9h0j1k2m3","dom_01hxa3b4c5d6e7f8g9h0j1k2m4"]`
- `enabled` (boolean, required) Example: `false`
- `confirmCancelPending` (boolean, optional): Only relevant when `enabled` is false. Set to true after the pending-orders confirmation response if the user wants to cancel those renewal orders. Example: `true`

### Request Examples

#### Enable auto-renew

```bash
curl -X POST "https://cloud.hostup.se/api/v2/domains/bulk/autorenew" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "domainIds": [
      "dom_01hxa3b4c5d6e7f8g9h0j1k2m3"
    ],
    "enabled": true
  }'
```

```json
{
  "domainIds": [
    "dom_01hxa3b4c5d6e7f8g9h0j1k2m3"
  ],
  "enabled": true
}
```

#### Disable auto-renew and cancel pending renewals after confirmation

```bash
curl -X POST "https://cloud.hostup.se/api/v2/domains/bulk/autorenew" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "domainIds": [
      "dom_01hxa3b4c5d6e7f8g9h0j1k2m3"
    ],
    "enabled": false,
    "confirmCancelPending": true
  }'
```

```json
{
  "domainIds": [
    "dom_01hxa3b4c5d6e7f8g9h0j1k2m3"
  ],
  "enabled": false,
  "confirmCancelPending": true
}
```

### Response Schema

- `pendingOrdersFound` (boolean, required)
  Allowed values: true
- `pendingOrders` (array<object>, required)
- `pendingOrders[].domainId` (string,null, required) Example: `dom_01hxa3b4c5d6e7f8g9h0j1k2m3`
- `pendingOrders[].domainName` (string,null, required) Example: `example.se`
- `pendingOrders[].orderId` (string,null, required) Example: `ord_01hxa3b4c5d6e7f8g9h0j1k2m4`
- `pendingOrders[].orderNumber` (string,null, required) Example: `123456`
- `pendingOrders[].invoiceId` (string,null, required) Example: `inv_01hxa3b4c5d6e7f8g9h0j1k2m5`
- `pendingOrders[].invoiceNumber` (string,null, required) Example: `202600001`
- `pendingOrders[].invoiceStatus` (string,null, required) Example: `Unpaid`
- `pendingOrders[].billing` (object, required)
- `pendingOrders[].billing.amount` (number,null, required) Example: `129`
- `pendingOrders[].billing.currencyCode` (string, required) Example: `SEK`
- `pendingOrders[].createdAt` (string,null, required) Example: `2026-04-27T12:00:00.000Z`

### Responses

#### 200 - Pending renewal orders must be confirmed before disabling auto-renew.
```json
{
  "pendingOrdersFound": true,
  "pendingOrders": [
    {
      "domainId": "dom_01hxa3b4c5d6e7f8g9h0j1k2m3",
      "domainName": "example.se",
      "orderId": "ord_01hxa3b4c5d6e7f8g9h0j1k2m4",
      "orderNumber": "123456",
      "invoiceId": "inv_01hxa3b4c5d6e7f8g9h0j1k2m5",
      "invoiceNumber": "202600001",
      "invoiceStatus": "Unpaid",
      "billing": {
        "amount": 129,
        "currencyCode": "SEK"
      },
      "createdAt": "2026-04-27T12:00:00.000Z"
    }
  ]
}
```

#### 202 - Bulk auto-renew job queued. Poll `operation.pollUrl` for completion.
```json
{
  "operation": {
    "status": "pending",
    "jobId": "dbj_01hxa3b4c5d6e7f8g9h0j1k2m3",
    "pollUrl": "/api/jobs/dbj_01hxa3b4c5d6e7f8g9h0j1k2m3"
  },
  "enabled": false,
  "domainsQueued": 2
}
```

#### 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"
}
```
