Create a device posture integration

Create a new device posture integration.

Script cloudflare Verified

by hugo697 ยท 11/16/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 383 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * Create a device posture integration
8
 * Create a new device posture integration.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  identifier: string,
13
  body: {
14
    config:
15
      | {
16
          api_url: string;
17
          auth_url: string;
18
          client_id: string;
19
          client_secret: string;
20
          [k: string]: unknown;
21
        }
22
      | {
23
          api_url: string;
24
          client_id: string;
25
          client_secret: string;
26
          customer_id: string;
27
          [k: string]: unknown;
28
        }
29
      | {
30
          api_url: string;
31
          client_key: string;
32
          client_secret: string;
33
          customer_id: string;
34
          [k: string]: unknown;
35
        }
36
      | {
37
          client_id: string;
38
          client_secret: string;
39
          customer_id: string;
40
          [k: string]: unknown;
41
        }
42
      | { client_id: string; client_secret: string; [k: string]: unknown }
43
      | { api_url: string; client_secret: string; [k: string]: unknown }
44
      | { api_url: string; client_secret: string; [k: string]: unknown };
45
    interval: string;
46
    name: string;
47
    type:
48
      | "workspace_one"
49
      | "crowdstrike_s2s"
50
      | "uptycs"
51
      | "intune"
52
      | "kolide"
53
      | "tanium"
54
      | "sentinelone_s2s";
55
    [k: string]: unknown;
56
  }
57
) {
58
  const url = new URL(
59
    `https://api.cloudflare.com/client/v4/accounts/${identifier}/devices/posture/integration`
60
  );
61

62
  const response = await fetch(url, {
63
    method: "POST",
64
    headers: {
65
      "X-AUTH-EMAIL": auth.email,
66
      "X-AUTH-KEY": auth.key,
67
      "Content-Type": "application/json",
68
      Authorization: "Bearer " + auth.token,
69
    },
70
    body: JSON.stringify(body),
71
  });
72
  if (!response.ok) {
73
    const text = await response.text();
74
    throw new Error(`${response.status} ${text}`);
75
  }
76
  return await response.json();
77
}
78