## POST /api/v2/orders/preview

**Preview an order**

Calculate pricing, tax, discounts, and validation requirements without creating an order or invoice. Authentication is optional: unauthenticated callers can preview a checkout cart, while authenticated callers may use stored account country/currency context. Use this after availability/product-detail lookup and before `POST /api/v2/orders` so the customer sees the exact total and any missing domain requirements. When supplied, `paymentMethod` is a checkout hint for the invoice that would be created: `card`, `swish`, `bankgiro`, `sepa`, or `invoice`. Account credit is handled after invoice creation.

### Related Endpoints

- `GET /api/v2/products/domains/{tld}`: Get TLD pricing and registry requirements
- `GET /api/v2/domains/availability`: Check domain availability
- `POST /api/v2/domains/availability`: Check bulk domain availability

### Headers

- `Accept`: application/json
- No authorization header required.
- `Content-Type`: application/json

### Request Body

- `items` (array<any>, optional)
- `clientData` (object, optional): Optional for authenticated API-key/session orders. Use only to override or provide missing profile fields returned by availability/validation requirements. Required for unauthenticated signup orders.
- `clientData.firstName` (string, optional) Example: `Anna`
- `clientData.lastName` (string, optional) Example: `Svensson`
- `clientData.companyName` (string, optional) Example: `Example AB`
- `clientData.email` (string, optional) Example: `user@example.com`
- `clientData.address` (object, optional)
- `clientData.address.street` (string, optional) Example: `Examplegatan 1`
- `clientData.address.address2` (string,null, optional) Example: `null`
- `clientData.address.city` (string, optional) Example: `Stockholm`
- `clientData.address.state` (string, optional) Example: `Stockholm`
- `clientData.address.postalCode` (string, optional) Example: `12345`
- `clientData.countryCode` (string, optional) Example: `SE`
- `clientData.phoneNumber` (string, optional) Example: `+46700000000`
- `clientData.registrationIdentifier` (object, optional)
- `clientData.registrationIdentifier.value` (string, optional) Example: `850507-3412`
- `clientData.registrationIdentifier.countryCode` (string,null, optional) Example: `SE`
- `clientData.vatNumber` (string, optional) Example: `SE559999999901`
- `clientData.accountType` (string, optional) Example: `private`
  Allowed values: private, organisation
- `paymentMethod` (string, optional): Canonical checkout preference for the invoice created by the order. Use `card` for card-backed hosted checkout flows, `swish` for Swish, `bankgiro` for Swedish SEK invoice payment, `sepa` for EUR SEPA bank transfer, or `invoice` to create the invoice without starting a specific payment flow. Provider names are not public v2 method values. Account credit is applied after invoice creation through the invoice credit action. Example: `card`
  Allowed values: card, swish, bankgiro, sepa, invoice
- `attemptKey` (string, optional): Optional caller-generated idempotency key for retry-safe order creation. Generate a fresh value for each logical order/checkout attempt and reuse that exact value only when retrying the same request after a timeout or lost response. If the previous attempt created an order, repeats with the same key within the duplicate-prevention window (currently one hour) return that existing order/invoice instead of creating another order. Do not reuse a key for a different cart. Example: `order_attempt_01hxa3b4c5d6e7f8g9h0j1k2m3`

### Request Examples

#### Preview .se registration

```bash
curl -X POST "https://cloud.hostup.se/api/v2/orders/preview" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "paymentMethod": "bankgiro",
    "items": [
      {
        "type": "domain",
        "action": "register",
        "domainName": "example.se",
        "years": 1,
        "acceptedTerms": [
          "se_registration_terms"
        ],
        "registrantContact": {
          "type": "private",
          "firstName": "Anna",
          "lastName": "Svensson",
          "email": "user@example.com",
          "phoneNumber": "+46700000000",
          "countryCode": "SE",
          "registrationIdentifier": {
            "value": "850507-3412",
            "countryCode": "SE"
          }
        }
      }
    ],
    "clientData": {
      "countryCode": "SE",
      "accountType": "private",
      "registrationIdentifier": {
        "value": "850507-3412",
        "countryCode": "SE"
      }
    }
  }'
```

```json
{
  "paymentMethod": "bankgiro",
  "items": [
    {
      "type": "domain",
      "action": "register",
      "domainName": "example.se",
      "years": 1,
      "acceptedTerms": [
        "se_registration_terms"
      ],
      "registrantContact": {
        "type": "private",
        "firstName": "Anna",
        "lastName": "Svensson",
        "email": "user@example.com",
        "phoneNumber": "+46700000000",
        "countryCode": "SE",
        "registrationIdentifier": {
          "value": "850507-3412",
          "countryCode": "SE"
        }
      }
    }
  ],
  "clientData": {
    "countryCode": "SE",
    "accountType": "private",
    "registrationIdentifier": {
      "value": "850507-3412",
      "countryCode": "SE"
    }
  }
}
```

#### Preview a domain transfer

```bash
curl -X POST "https://cloud.hostup.se/api/v2/orders/preview" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "paymentMethod": "invoice",
    "items": [
      {
        "type": "domain",
        "action": "transfer",
        "domainName": "example.com",
        "years": 1,
        "eppCode": "YOUR_EPP_CODE"
      }
    ]
  }'
```

```json
{
  "paymentMethod": "invoice",
  "items": [
    {
      "type": "domain",
      "action": "transfer",
      "domainName": "example.com",
      "years": 1,
      "eppCode": "YOUR_EPP_CODE"
    }
  ]
}
```

### Response Schema

- `items` (array<object>, optional)
- `items[].productSlug` (string,null, required) Example: `vps-med`
- `items[].domainName` (string,null, required) Example: `null`
- `items[].type` (string, required) Example: `vps`
  Allowed values: vps, shared_hosting, addon, domain
- `items[].billingCycle` (string,null, required) Example: `annually`
- `items[].periodYears` (integer,null, optional): Present for multi-year domain previews. Example: `1`
- `items[].quantity` (integer, required) Example: `1`
- `items[].unitAmount` (number, required) Example: `1440`
- `items[].setupAmount` (number, required) Example: `0`
- `items[].configurableOptionAmounts` (array<object>, required)
- `items[].configurableOptionAmounts[].key` (string, required) Example: `backupSlots`
- `items[].configurableOptionAmounts[].label` (string, required) Example: `Example Label`
- `items[].configurableOptionAmounts[].amount` (number, required) Example: `0`
- `items[].configurableOptionAmounts[].quantity` (number,null, required) Example: `7`
- `items[].subtotal` (number, required) Example: `1440`
- `items[].currencyCode` (string, required) Example: `SEK`
- `subtotal` (number, optional) Example: `1440`
- `taxRateDecimal` (number, optional) Example: `0.25`
- `taxAmount` (number, optional) Example: `360`
- `total` (number, optional) Example: `1800`
- `currencyCode` (string, optional) Example: `SEK`
- `reverseCharge` (boolean, optional) Example: `false`
- `priceAssurance` (object, optional)
- `priceAssurance.level` (string, required) Example: `authoritative`
  Allowed values: authoritative, provisional
- `priceAssurance.reason` (string,null, required) Example: `null`
- `priceAssurance.revalidatedAtSubmit` (boolean, required) Example: `false`

### Responses

#### 200 - Order price preview.
```json
{
  "items": [
    {
      "productSlug": "domain-se",
      "domainName": "example.se",
      "type": "domain",
      "billingCycle": "annually",
      "periodYears": 1,
      "quantity": 1,
      "unitAmount": 79,
      "setupAmount": 0,
      "configurableOptionAmounts": [],
      "subtotal": 79,
      "currencyCode": "SEK"
    }
  ],
  "subtotal": 79,
  "taxRateDecimal": 0.25,
  "taxAmount": 19.75,
  "total": 98.75,
  "currencyCode": "SEK",
  "reverseCharge": false,
  "priceAssurance": {
    "level": "authoritative",
    "reason": null,
    "revalidatedAtSubmit": false
  }
}
```

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

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