0
Patch discovered operation
One script reply has been approved by the moderators Verified

Update the state on a discovered operation

Created by hugo697 103 days ago Viewed 5 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 103 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * Patch discovered operation
8
 * Update the `state` on a discovered operation
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  zone_id: string,
13
  operation_id: string,
14
  body: { state?: "review" | "ignored"; [k: string]: unknown }
15
) {
16
  const url = new URL(
17
    `https://api.cloudflare.com/client/v4/zones/${zone_id}/api_gateway/discovery/operations/${operation_id}`
18
  );
19

20
  const response = await fetch(url, {
21
    method: "PATCH",
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: JSON.stringify(body),
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