0

Update a CDN Endpoint

by
Published Dec 20, 2024

To update the TTL, certificate ID, or the FQDN of the custom subdomain for an existing CDN endpoint, send a PUT request to `/v2/cdn/endpoints/$ENDPOINT_ID`.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Update a CDN Endpoint
7
 * To update the TTL, certificate ID, or the FQDN of the custom subdomain for
8
an existing CDN endpoint, send a PUT request to
9
`/v2/cdn/endpoints/$ENDPOINT_ID`.
10

11
 */
12
export async function main(
13
  auth: Digitalocean,
14
  cdn_id: string,
15
  body: {
16
    ttl?: 60 | 600 | 3600 | 86400 | 604800;
17
    certificate_id?: string;
18
    custom_domain?: string;
19
  },
20
) {
21
  const url = new URL(
22
    `https://api.digitalocean.com/v2/cdn/endpoints/${cdn_id}`,
23
  );
24

25
  const response = await fetch(url, {
26
    method: "PUT",
27
    headers: {
28
      "Content-Type": "application/json",
29
      Authorization: "Bearer " + auth.token,
30
    },
31
    body: JSON.stringify(body),
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39