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

**Set the default card**

Makes a saved card the account's default card. Automatic charges use the default card. Paying an invoice with a saved card also uses it when you choose no other card. Send no body. Calling it on the current default changes nothing and still returns 200. The response is the full card list, with `isPrimary: true` on the new default.

### Related Endpoints

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

### Headers

- `Authorization`: Bearer $HOSTUP_API_KEY
- Scope: `write:payment_methods`

### Parameters

- `id` (path, string, required): The card ID (`card_…`). 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 $HOSTUP_API_KEY" \
  -H "Content-Type: application/json"
```

### Responses

#### 200 - The full saved-card list with the new default.
```json
[
  {
    "id": "card_01hxa3b4c5d6e7f8g9h0j1k2m3",
    "brand": "visa",
    "last4": "4242",
    "expMonth": 12,
    "expYear": 2028,
    "cardholderName": "Alex Example",
    "isPrimary": true,
    "addedAt": "2026-04-27T12:00:00.000Z"
  },
  {
    "id": "card_01hxa3b4c5d6e7f8g9h0j1k2m4",
    "brand": "mastercard",
    "last4": "4444",
    "expMonth": 3,
    "expYear": 2027,
    "cardholderName": "Alex Example",
    "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 is invalid.",
  "code": "invalid_request",
  "instance": "/api/v2/resource",
  "requestId": "req_01hxa3b4c5d6e7f8g9h0j1k2m3",
  "timestamp": "2026-04-27T12:34:56.000Z"
}
```

#### 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 API key lacks `write:payment_methods`. A session that is not the account owner gets it too.
```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": "Rate limit exceeded. Please try again later.",
  "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 default card could not be changed. Try again shortly.
```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"
}
```
