# Upload a certificate for a domain

Source: https://openpanel.sh/docs/api/domains/upload-a-certificate-for-a-domain

For your own domain once it is verified: a certificate chain and its private key, which the edge then serves for that domain instead of its own. It is refused unless the chain is in order, its first certificate covers the domain and is valid now, and the key matches it. The key is kept sealed and never returned; replacing uploads over the one before.

`PUT https://openpanel.sh/api/v1/domains/{domainId}/certificate`

## Parameters

| Name | In | Required | Description |
|---|---|---|---|
| `domainId` | path | yes |  |

## Request body

JSON, `CertificateUpload`.

## Responses

| Status | Meaning | Body |
|---|---|---|
| 200 | Upload a certificate for a domain | `application/json`, `DomainWithCertificate` |
| 401 | No valid credential was sent. | `application/problem+json`, `Problem` |
| 403 | The credential may not do this. | `application/problem+json`, `Problem` |
| 404 | Not found, or not visible to this credential. | `application/problem+json`, `Problem` |
| 409 | It clashes with something that exists, such as a name in use. | `application/problem+json`, `Problem` |
| 422 | The input was refused; detail says why. | `application/problem+json`, `Problem` |
| 429 | Too many requests; wait for Retry-After seconds. | `application/problem+json`, `Problem` |

## Schemas

### Certificate

```json
{
  "type": "object",
  "properties": {
    "names": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "The names the certificate covers."
    },
    "issuer": {
      "type": "string"
    },
    "notBefore": {
      "type": "string",
      "format": "date-time"
    },
    "notAfter": {
      "type": "string",
      "format": "date-time"
    },
    "fingerprint": {
      "type": "string",
      "description": "SHA-256 of the certificate."
    }
  },
  "required": [
    "names",
    "issuer",
    "notBefore",
    "notAfter",
    "fingerprint"
  ]
}
```

### CertificateUpload

```json
{
  "type": "object",
  "properties": {
    "chain": {
      "type": "string",
      "maxLength": 65536,
      "description": "The certificate and its intermediates in PEM, your domain's certificate first."
    },
    "key": {
      "type": "string",
      "maxLength": 16384,
      "description": "The certificate's private key in PEM, without a passphrase. Kept sealed and never returned."
    }
  },
  "required": [
    "chain",
    "key"
  ],
  "additionalProperties": false
}
```

### DnsRecord

```json
{
  "type": "object",
  "properties": {
    "type": {
      "type": "string",
      "enum": [
        "CNAME",
        "TXT"
      ]
    },
    "name": {
      "type": "string"
    },
    "value": {
      "type": "string"
    },
    "purpose": {
      "type": "string"
    }
  },
  "required": [
    "type",
    "name",
    "value",
    "purpose"
  ]
}
```

### DomainWithCertificate

```json
{
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid"
    },
    "serviceId": {
      "type": "string",
      "format": "uuid"
    },
    "projectId": {
      "type": "string",
      "format": "uuid"
    },
    "host": {
      "type": "string"
    },
    "kind": {
      "type": "string",
      "enum": [
        "opnl",
        "custom"
      ]
    },
    "port": {
      "type": "integer"
    },
    "verifyToken": {
      "type": [
        "string",
        "null"
      ]
    },
    "verifiedAt": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time"
        },
        {
          "type": "null"
        }
      ]
    },
    "certificateSource": {
      "type": "string",
      "enum": [
        "auto",
        "uploaded"
      ],
      "description": "uploaded: the edge serves the certificate you uploaded for this domain."
    },
    "certificateExpiresAt": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time"
        },
        {
          "type": "null"
        }
      ],
      "description": "When the uploaded certificate expires."
    },
    "dnsZoneId": {
      "anyOf": [
        {
          "type": "string",
          "format": "uuid"
        },
        {
          "type": "null"
        }
      ],
      "description": "The connected Cloudflare zone in which OpenPanel wrote this domain's records; null when you add them yourself."
    },
    "dnsProblem": {
      "description": "Why OpenPanel could not write a record in that zone, such as a name that already has one.",
      "type": [
        "string",
        "null"
      ]
    },
    "createdAt": {
      "type": "string",
      "format": "date-time"
    },
    "records": {
      "type": "array",
      "items": {
        "$ref": "#/components/schemas/DnsRecord"
      },
      "description": "For your own domain: the DNS records to add."
    },
    "certificate": {
      "$ref": "#/components/schemas/Certificate"
    }
  },
  "required": [
    "id",
    "serviceId",
    "projectId",
    "host",
    "kind",
    "port",
    "verifyToken",
    "verifiedAt",
    "certificateSource",
    "certificateExpiresAt",
    "dnsZoneId",
    "dnsProblem",
    "createdAt",
    "records",
    "certificate"
  ]
}
```

### Problem

```json
{
  "type": "object",
  "properties": {
    "type": {
      "type": "string",
      "description": "A link to the error's explanation in the docs."
    },
    "title": {
      "type": "string"
    },
    "status": {
      "type": "integer"
    },
    "code": {
      "type": "string",
      "description": "Stable machine-readable code: not_found, forbidden, invalid, conflict, rate_limited, not_implemented, …"
    },
    "detail": {
      "type": "string",
      "description": "What went wrong, in a sentence written for a person."
    }
  },
  "required": [
    "type",
    "title",
    "status",
    "code",
    "detail"
  ]
}
```