## POST /api/v2/billing/cards/{id}/actions/set-default

**Set default saved card**

Make one saved card the account's default: the card that automatic payments and pay-with-saved-card use unless another card is chosen for a specific payment. Get `{id}` from `GET /api/v2/billing/cards` entries. Send no body. Only the account owner can change payment methods; contact and delegated billing sessions get 403 `forbidden`. A card that does not exist or belongs to another account returns 404 `card_not_found`. Calling it on the card that is already the default succeeds and changes nothing. The response is the full refreshed card list with `isPrimary: true` on the new default. To remove a card use `DELETE /api/v2/billing/cards/{id}`.

### Related Endpoints

- `DELETE /api/v2/billing/cards/{id}`: Delete saved card
- `GET /api/v2/billing/cards`: List saved cards
- `POST /api/v2/billing/cards`: Store saved card

### Headers

- `Accept`: application/json
- `Authorization`: Bearer YOUR_API_KEY
- Required API scope: `write:payment_methods`

### Parameters

- `id` (path, string, required): Public card ID from `GET /api/v2/billing/cards` response entries. Do not invent this value; use the exact ID returned by the referenced API response. Example: `card_01hxa3b4c5d6e7f8g9h0j1k2m3`

### Request Example

```bash
curl -X POST "https://cloud.hostup.se/api/v2/billing/cards/card_01hxa3b4c5d6e7f8g9h0j1k2m3/actions/set-default" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Accept: application/json"
```

### Responses

#### 200 - Default card changed. The full saved-card list with `isPrimary` updated.
```json
[
  {
    "id": "card_01hxa3b4c5d6e7f8g9h0j1k2m3",
    "brand": "visa",
    "last4": "4242",
    "expMonth": 12,
    "expYear": 2028,
    "cardholderName": "Example Customer",
    "isPrimary": true,
    "addedAt": "2026-04-27T12:00:00.000Z"
  },
  {
    "id": "card_01hxb7c8d9e0f1g2h3j4k5m6n7",
    "brand": "mastercard",
    "last4": "4444",
    "expMonth": 3,
    "expYear": 2027,
    "cardholderName": "Example Customer",
    "isPrimary": false,
    "addedAt": "2025-11-02T09:30:00.000Z"
  }
]
```

#### 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 - The session is not the account owner.
```json
{
  "type": "https://developer.hostup.se/errors/forbidden",
  "title": "Forbidden",
  "status": 403,
  "detail": "Account-owner access is required to change the default card.",
  "code": "forbidden",
  "instance": "/api/v2/billing/cards/card_01hxa3b4c5d6e7f8g9h0j1k2m3/actions/set-default"
}
```

#### 404 - No saved card with this ID on the account.
```json
{
  "type": "https://developer.hostup.se/errors/card_not_found",
  "title": "Card not found",
  "status": 404,
  "detail": "The requested payment card could not be found.",
  "code": "card_not_found",
  "instance": "/api/v2/billing/cards/card_01hxa3b4c5d6e7f8g9h0j1k2m3/actions/set-default"
}
```

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

#### 502 - The billing provider did not accept the change.
```json
{
  "type": "https://developer.hostup.se/errors/upstream_failed",
  "title": "Upstream request failed",
  "status": 502,
  "detail": "The default card could not be changed right now. Please try again in a moment.",
  "code": "upstream_failed",
  "instance": "/api/v2/billing/cards/card_01hxa3b4c5d6e7f8g9h0j1k2m3/actions/set-default"
}
```
