0

Create Origin CA Certificate

by
Published today

Issue a Cloudflare Origin CA certificate for your origin server from a CSR you generated. requested_validity is in days: 7, 30, 90, 365, 730, 1095 or 5475 (default).

Script cloudflare Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 3 hours ago
1
//native
2

3
/**
4
 * Create Origin CA Certificate
5
 * Issue a Cloudflare Origin CA certificate for your origin server from a CSR you generated. requested_validity is in days: 7, 30, 90, 365, 730, 1095 or 5475 (default).
6
 */
7
export async function main(
8
  auth: RT.Cloudflare,
9
  csr: string,
10
  hostnames: string[],
11
  request_type: "origin-rsa" | "origin-ecc",
12
  requested_validity: number | undefined
13
) {
14
  const response = await fetch(
15
    "https://api.cloudflare.com/client/v4/certificates",
16
    {
17
      method: "POST",
18
      headers: {
19
        Authorization: `Bearer ${auth.token}`,
20
        "Content-Type": "application/json",
21
        Accept: "application/json",
22
      },
23
      body: JSON.stringify({
24
        csr,
25
        hostnames,
26
        request_type,
27
        requested_validity: requested_validity ?? 5475,
28
      }),
29
    }
30
  )
31

32
  if (!response.ok) {
33
    throw new Error(`${response.status} ${await response.text()}`)
34
  }
35

36
  return await response.json()
37
}
38