0
Rollback deployment
One script reply has been approved by the moderators Verified

Rollback the production deployment to a previous deployment. You can only rollback to succesful builds on production.

Created by hugo697 297 days ago Viewed 8999 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 297 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * Rollback deployment
8
 * Rollback the production deployment to a previous deployment. You can only rollback to succesful builds on production.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  deployment_identifier: string,
13
  project_name: string,
14
  account_identifier: string
15
) {
16
  const url = new URL(
17
    `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/pages/projects/${project_name}/deployments/${deployment_identifier}/rollback`
18
  );
19

20
  const response = await fetch(url, {
21
    method: "POST",
22
    headers: {
23
      "X-AUTH-EMAIL": auth.email,
24
      "X-AUTH-KEY": auth.key,
25
      "Content-Type": "application/json",
26
      Authorization: "Bearer " + auth.token,
27
    },
28
    body: undefined,
29
  });
30
  if (!response.ok) {
31
    const text = await response.text();
32
    throw new Error(`${response.status} ${text}`);
33
  }
34
  return await response.json();
35
}
36