# Certificates

Upload your own edge certificates, issue origin certificates and read every certificate of a domain.

A domain has two kinds of certificate. Edge certificates are the ones visitors see: the universal certificate, and the custom ones you upload. Origin certificates are issued by the CDN for your origin server. The paths start with `/v2/cdn/certificates/{domain_public_id}/`, where the id is the public id of the domain, taken from [the domains list](https://docs.diamwall.com/products/domains/#list-your-domains).

- [Overview](#overview-of-a-domain): Every certificate of the domain in one cheap read.
- [Edge certificates](#edge-certificates): List, upload, read and delete custom certificates.
- [Origin certificates](#origin-certificates): Issue a certificate for your origin, read it and delete it.

The examples on this page use these shell variables:

```bash
export DIAMWALL_API_KEY="your key"
export CERTS="https://api.diamwall.com/v2/cdn/certificates/your-domain-public-id"
```

## How the answers read

### No read returns a key or a PEM

A read answers the public metadata of a certificate, under `certificate.value`: `subject`, `issuer`, `hostnames`, `not_before`, `not_after`, `fingerprint_sha256` and `status`. The `status` is `active`, `expired` or `not_yet_valid`.

The private key of a custom certificate you upload is never answered back. The private key of an origin certificate is answered once, by the call that creates it.

### Unknown is not empty

Most values come with a `state`. Only `resolved` carries a value you can show.

| What you see | What it means |
| --- | --- |
| `state: "resolved"` with a value | The value was read. |
| `state: "resolved"` with `items: []` or `value: []` | The domain has no certificate of that kind. |
| `state: "unknown"` | The value is unavailable. A `reason` may say why. |
| `state: "unrecognized"` | A state this API does not know. Treat it as unavailable. |

Show `unknown` as unavailable. It never means that the domain has no certificate, and never that a certificate is healthy.

### Writes need the latest revision

Each of the two collections has a revision. A read of a collection, or of one certificate in it, answers that revision in the `ETag` header. Every create and delete sends it back in `If-Match`, exactly as it came, with its quotes.

- Without `If-Match` the write answers `428 PRECONDITION_REQUIRED`.
- If the collection changed since your read, it answers `412 REVISION_MISMATCH`. Read again and retry.
- A weak ETag, `*`, a list or a value without quotes answers `400 INVALID_PRECONDITION`.
- Every write answers a new `ETag` to use on the next one.

The edge collection and the origin collection have separate revisions. Use the `ETag` of the one you write to.

## Overview of a domain

[`GET /v2/cdn/certificates/{domain_public_id}/settings/certificates/` in the API reference](https://docs.diamwall.com/api/#tag/certificates/GET/v2/cdn/certificates/{domain_public_id}/settings/certificates/)

One read answers the universal certificate, the custom edge certificates and the origin certificates together. It costs 8 credits, where a read of either collection costs 60, so use it to draw a page of certificates.

```bash
curl "$CERTS/settings/certificates/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY"
```

```json
{
  "revision": "sha256:f315781722ba...",
  "consistency": "verified",
  "data": {
    "certificate_verification_enabled": false,
    "edge": {
      "universal": {
        "state": "resolved",
        "value": {
          "certificate": {
            "state": "resolved",
            "value": {
              "subject": "CN=example.com",
              "hostnames": ["example.com", "www.example.com"],
              "not_after": "2027-10-10T00:00:00.000Z",
              "status": "active"
            }
          }
        }
      },
      "custom": { "state": "resolved", "value": [] }
    },
    "origin": { "state": "resolved", "value": [] }
  }
}
```

| Field | What it holds |
| --- | --- |
| `data.edge.universal` | The universal certificate. A `value` of `null` under `resolved` means the domain has none. |
| `data.edge.custom` | The custom edge certificates, as their collection lists them. |
| `data.origin` | The origin certificates, the deleted ones included. |
| `data.certificate_verification_enabled` | Whether verification of the origin's TLS certificate is enabled. When the field is absent the value is unavailable, not `false`. |

- This endpoint is read-only and answers no `ETag`. Certificates are created and deleted through the two collections below.
- When the whole group is unavailable, the answer is still `200`, with a top-level `state` of `unknown`, a `revision` of `null` and no `data`.
- `certificate_verification_enabled` only says the setting is on. It does not say that a check of the origin's certificate passed.

## Edge certificates

The edge collection holds the custom certificates you uploaded and, when the domain has one, the universal certificate. The universal certificate has the id `universal`. You can read it, but not delete it.

### List the edge certificates

[`GET /v2/cdn/certificates/{domain_public_id}/edge-certificates/` in the API reference](https://docs.diamwall.com/api/#tag/certificates/GET/v2/cdn/certificates/{domain_public_id}/edge-certificates/)

```bash
curl "$CERTS/edge-certificates/?limit=50" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY"
```

```json
{
  "revision": "sha256:118dfdf1af1e...",
  "consistency": "verified",
  "data": {
    "state": "resolved",
    "items": [
      {
        "id": "0123456789abcdef",
        "type": "custom",
        "primary_hostname": "example.com",
        "hostnames": ["example.com", "www.example.com"],
        "uploaded_at": "2026-10-10T00:00:00.000Z",
        "key_status": {
          "state": "resolved",
          "value": { "algorithm": "ec", "matches_certificate": true, "present": true }
        },
        "certificate": {
          "state": "resolved",
          "value": {
            "subject": "CN=example.com",
            "issuer": "CN=Example Issuing CA",
            "hostnames": ["example.com", "www.example.com"],
            "not_before": "2026-10-10T00:00:00.000Z",
            "not_after": "2027-10-10T00:00:00.000Z",
            "status": "active"
          }
        }
      }
    ],
    "page": { "limit": 50, "next_cursor": null, "total": 1 }
  }
}
```

- `limit` goes from 1 to 100. Without it a page holds 50 certificates. No other query parameter is accepted besides `limit` and `cursor`.
- To read the next page, send `data.page.next_cursor` back as `cursor`, until it is `null`.
- If the collection changes between two pages, the next page answers `409 CURSOR_STALE`. Start again from the first page.
- Check `data.state` first. When it is not `resolved`, the answer is still `200`, but it has no `items`, no `page` and no `ETag`: the certificates are unavailable.
- The universal item has `type: "universal"` and no hostnames or upload date of its own. If its `certificate.state` is `unknown`, show it as unavailable.

### Upload a custom certificate

[`POST /v2/cdn/certificates/{domain_public_id}/edge-certificates/` in the API reference](https://docs.diamwall.com/api/#tag/certificates/POST/v2/cdn/certificates/{domain_public_id}/edge-certificates/)

Read the collection first to get the `ETag`:

```bash
ETAG=$(curl -s -o /dev/null -D - "$CERTS/edge-certificates/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  | tr -d '\r' | awk 'tolower($1) == "etag:" { print $2 }')
```

Then send the certificate and its private key, each as a PEM string. `jq` builds the JSON body from the two files:

```bash
jq -n --rawfile cert fullchain.pem --rawfile key privkey.pem \
  '{ certificate: $cert, private_key: $key, hostnames: ["example.com", "www.example.com"] }' \
  | curl -X POST "$CERTS/edge-certificates/" \
      -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
      -H "Content-Type: application/json" \
      -H "If-Match: $ETAG" \
      -d @-
```

| Field | Required | Rules |
| --- | --- | --- |
| `certificate` | Yes | A PEM string, not empty, at most 1 MiB. |
| `private_key` | Yes | A PEM string, not empty, at most 1 MiB. |
| `hostnames` | No | 1 to 100 hostnames of 1 to 253 characters, each once. Each has to belong to the domain and be covered by the certificate. Without it, the hostnames are taken from the certificate. |

The whole body holds at most 3 MiB. Any other field is refused.

The answer is `201` with the new certificate under `data`, its id in `operation.id`, and a new `ETag` header. Neither the certificate nor the key you sent is answered back.

The certificate has to match its key, be valid now and for at least 14 more days, and cover hostnames of the domain. Otherwise the upload is refused and nothing is written. See [the error table](#errors-you-are-likely-to-see) for the codes.

> **When the answer does not come**
> After `502 FILE_SERVER_OUTCOME_UNKNOWN` or `503 READBACK_MISMATCH` the certificate may have been created. Read the collection before you try anything else. Never send the upload again blindly.

### Read one edge certificate

[`GET /v2/cdn/certificates/{domain_public_id}/edge-certificates/{certificate_id}/` in the API reference](https://docs.diamwall.com/api/#tag/certificates/GET/v2/cdn/certificates/{domain_public_id}/edge-certificates/{certificate_id}/)

The id is the `id` from the list: 16 lowercase hexadecimal digits for a custom certificate, or `universal`.

```bash
curl "$CERTS/edge-certificates/0123456789abcdef/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY"
```

The `ETag` header of the answer is the revision of the whole collection, so you can use it in `If-Match` for a delete. An id in the wrong form answers `400 INVALID_REQUEST`. An id that no certificate has answers `404 RESOURCE_ITEM_NOT_FOUND`.

### Delete a custom certificate

[`DELETE /v2/cdn/certificates/{domain_public_id}/edge-certificates/{certificate_id}/` in the API reference](https://docs.diamwall.com/api/#tag/certificates/DELETE/v2/cdn/certificates/{domain_public_id}/edge-certificates/{certificate_id}/)

```bash
curl -X DELETE "$CERTS/edge-certificates/0123456789abcdef/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "If-Match: $ETAG"
```

The answer has no `data`. `operation.id` is the id the certificate had, and the `ETag` header is the new revision of the collection.

The universal certificate cannot be deleted: the id `universal` answers `400 INVALID_REQUEST`. After `502 FILE_SERVER_OUTCOME_UNKNOWN` or `503 READBACK_MISMATCH` the certificate may have been deleted, so read the collection before you try again.

## Origin certificates

An origin certificate is issued by the CDN for the origin of the domain. The CDN generates the key and the certificate, and answers both once. You install them on your origin server.

### List the origin certificates

[`GET /v2/cdn/certificates/{domain_public_id}/origin-certificates/` in the API reference](https://docs.diamwall.com/api/#tag/certificates/GET/v2/cdn/certificates/{domain_public_id}/origin-certificates/)

```bash
curl "$CERTS/origin-certificates/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY"
```

Each item has its `id`, `hostnames`, `key_type`, `created_at`, `revoked`, `revoked_at` and the public metadata under `certificate`. Paging, `data.state` and the `ETag` work the same way as for [the edge list](#list-the-edge-certificates).

A deleted certificate stays in the list, with `revoked: true`, a `revoked_at` date and a `certificate` with no `value`.

### Create an origin certificate

[`POST /v2/cdn/certificates/{domain_public_id}/origin-certificates/` in the API reference](https://docs.diamwall.com/api/#tag/certificates/POST/v2/cdn/certificates/{domain_public_id}/origin-certificates/)

Read the origin collection to get its `ETag`, then send the create. Every field of the body is optional, but the body itself is required: send `{}` to take the defaults.

```bash
ORIGIN_ETAG=$(curl -s -o /dev/null -D - "$CERTS/origin-certificates/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  | tr -d '\r' | awk 'tolower($1) == "etag:" { print $2 }')

curl -X POST "$CERTS/origin-certificates/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "If-Match: $ORIGIN_ETAG" \
  -o origin-certificate.json \
  -d '{
    "hostnames": ["example.com", "*.example.com"],
    "validity_years": 5,
    "key_type": "rsa"
  }'
```

| Field | Allowed values | Without it |
| --- | --- | --- |
| `hostnames` | A list of hostnames of the domain, 1 to 253 characters each | The domain and its wildcard |
| `validity_years` | `1`, `2`, `3`, `5`, `10` or `15`, as a number | `15` |
| `key_type` | `ecdsa` or `rsa` | `ecdsa` |

The answer is `201`. The certificate's metadata is under `data`, and the material is under `operation.result`:

```json
{
  "data": { "id": "76543210fedcba98", "key_type": "ecdsa", "revoked": false },
  "operation": {
    "type": "create",
    "id": "76543210fedcba98",
    "result": {
      "not_before": "2026-10-10T00:00:00.000Z",
      "not_after": "2041-10-10T00:00:00.000Z",
      "delivery": "one_time",
      "certificate": "-----BEGIN CERTIFICATE-----...",
      "ca_certificate": "-----BEGIN CERTIFICATE-----...",
      "private_key": "-----BEGIN PRIVATE KEY-----..."
    }
  }
}
```

> **The private key is answered once**
> Store `operation.result.private_key` before you discard the answer. No read returns it and it cannot be had again. The example above writes the answer to a file for that reason. Keep that file safe.

A certificate whose key you do not have cannot be used. That happens when:

- the `201` has no `operation.result`, or no `private_key` in it;
- the answer was lost: `502 FILE_SERVER_OUTCOME_UNKNOWN`, or `503` with `READBACK_MISMATCH`, `GENERATION_FAILED` or `ISSUANCE_VERIFICATION_FAILED`.

In both cases, read the collection first. If it lists a certificate this request created, delete it, and only then create another. Do not repeat the request blindly: every certificate that was created stays in the history of the domain, and that history has a ceiling.

### Read one origin certificate

[`GET /v2/cdn/certificates/{domain_public_id}/origin-certificates/{certificate_id}/` in the API reference](https://docs.diamwall.com/api/#tag/certificates/GET/v2/cdn/certificates/{domain_public_id}/origin-certificates/{certificate_id}/)

```bash
curl "$CERTS/origin-certificates/76543210fedcba98/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY"
```

The id is 16 lowercase hexadecimal digits. The answer never holds the private key. If you lost the key, delete the certificate and create another. The `ETag` header is the revision of the whole origin collection.

### Delete an origin certificate

[`DELETE /v2/cdn/certificates/{domain_public_id}/origin-certificates/{certificate_id}/` in the API reference](https://docs.diamwall.com/api/#tag/certificates/DELETE/v2/cdn/certificates/{domain_public_id}/origin-certificates/{certificate_id}/)

```bash
curl -X DELETE "$CERTS/origin-certificates/76543210fedcba98/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "If-Match: $ORIGIN_ETAG"
```

The answer has no `data`. Read the collection to see the entry as it is now.

> **A delete keeps the entry**
> - The certificate stays listed, with `revoked: true`, and still counts toward the history of the domain.
> - The delete cannot be undone, and the key cannot be had again.
> - The delete does not tell you that the edge now refuses the certificate.

## Limits and permissions

- **Plan.** Every endpoint on this page needs the Business or Enterprise plan. On any other plan the call answers `403 FEATURE_NOT_AVAILABLE`, with `details.feature` (`custom_certificates` or `origin_certificates`) and `details.plan`, and spends no credits.
- **Custom certificate limit.** A Business domain has 1 custom certificate. An Enterprise domain has no limit. The universal certificate does not count. An upload at the limit answers `400 PLAN_LIMIT_EXCEEDED`, with `details.limit` and `details.plan`.
- **Credits.** Each domain has a budget of 3000 credits a minute, shared by everyone who calls the API for that domain.
- **Out of credits.** The call answers `429 TOO_MANY_REQUESTS`, with the wait in `details.retry_after_seconds`.
- **Refused early.** A request refused before it reaches the CDN (a `400` for its body, id or `If-Match`, a `403`, a `413` or a `428`) spends no credits.

| Call | Cost |
| --- | --- |
| `GET .../settings/certificates/` | 8 credits |
| A read of either collection | 60 credits |
| Upload a custom certificate, on a plan with no limit | 60 credits |
| Upload a custom certificate, on a plan with a limit | 120 credits |
| Create an origin certificate | 60 credits |
| Delete an edge or origin certificate | 60 credits |

> **An upload on Business takes the whole minute**
> On a plan with a certificate limit, the upload reads the collection first, so it costs 120 credits. It only runs when nothing else was spent on the domain in the last minute, and no other call runs for a minute after it. A `429` says how long to wait. An upload refused with `PLAN_LIMIT_EXCEEDED`, or with the `412` of that first read, still spends the 120 credits.

| Action | Permission on the domain |
| --- | --- |
| Any read | `ssl.view` |
| Upload a custom certificate, create an origin certificate | `ssl.create` |
| Delete a custom certificate | `ssl.delete` |
| Delete an origin certificate | `ssl.edit`. Whoever holds `ssl.create` or `ssl.delete` holds it too. |

## Errors you are likely to see

| Status | Code | What happened |
| --- | --- | --- |
| `400` | `INVALID_REQUEST` | A field, a query parameter or the certificate id is wrong. The answer names it in `fields` when it can. An origin create with no body answers this too. |
| `400` | `INVALID_PRECONDITION` | The `If-Match` is not one quoted strong ETag. |
| `400` | `PLAN_LIMIT_EXCEEDED` | The domain is at the custom certificate limit of its plan. |
| `400` | `INVALID_CERTIFICATE` | The certificate you uploaded was refused as invalid. |
| `400` | `PRIVATE_KEY_MISMATCH` | The private key does not match the certificate. |
| `400` | `CERTIFICATE_EXPIRED`, `CERTIFICATE_EXPIRING`, `CERTIFICATE_NOT_YET_VALID` | The certificate is not valid now and for 14 more days. |
| `400` | `CERTIFICATE_HOSTNAME_MISMATCH` | The certificate does not cover the hostnames. |
| `400` | `INVALID_HOSTNAMES`, `HOSTNAMES_UNAVAILABLE` | The hostnames were refused. |
| `400` | `INVALID_KEY_TYPE`, `INVALID_VALIDITY` | The `key_type` or `validity_years` of an origin certificate was refused. |
| `403` | `FEATURE_NOT_AVAILABLE` | The domain's plan does not include certificates. |
| `404` | `RESOURCE_ITEM_NOT_FOUND` | No certificate has that id. |
| `409` | `CURSOR_STALE` | The collection changed while you were paging. Start from the first page. |
| `409` | `HOSTNAME_CONFLICT` | The upload was refused over its hostnames. Nothing was written. |
| `409` | `QUOTA_EXCEEDED` | The CDN's own ceiling of certificates was reached. This is not the plan limit. |
| `409` | `ARTIFACT_CONFLICT` | The create was refused for the state of the domain's certificates. Nothing was written. |
| `412` | `REVISION_MISMATCH` | The collection changed since your read. Read again and retry. |
| `413` | `PAYLOAD_TOO_LARGE` | The body is larger than 3 MiB. |
| `428` | `PRECONDITION_REQUIRED` | The `If-Match` header is missing. |
| `429` | `TOO_MANY_REQUESTS` | The domain is out of credits for now. |
| `502` | `FILE_SERVER_OUTCOME_UNKNOWN` | The write may have been made. Read the collection before anything else. |
| `503` | `READBACK_MISMATCH` | The outcome of the write is unconfirmed. Read the collection before anything else. |
| `503` | `GENERATION_FAILED`, `ISSUANCE_VERIFICATION_FAILED` | An origin create failed part way. The outcome is unconfirmed. Read the collection. |
| `503` | `ORIGIN_CA_UNAVAILABLE` | The origin certificate could not be issued right now. Nothing was created. |

The errors that come from the key itself, such as `API_KEY_IP_NOT_ALLOWED`, are on the [Errors](https://docs.diamwall.com/reference/errors/) page.

## All Certificates endpoints

Each row opens the endpoint in the API reference, with every parameter, rule and response.

See the [API reference](https://docs.diamwall.com/api/#tag/certificates) for every endpoint, with parameters and responses.
