0

Update a user's grants

by
Published Oct 17, 2025

Update the grants a user has.

Script linode Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Linode = {
3
  token: string;
4
};
5
/**
6
 * Update a user's grants
7
 * Update the grants a user has.
8
 */
9
export async function main(
10
  auth: Linode,
11
  apiVersion: "v4" | "v4beta",
12
  username: string,
13
  body: {
14
    database?: {
15
      id?: number;
16
      label?: string;
17
      permissions?: "read_only" | "read_write";
18
    }[];
19
    domain?: {
20
      id?: number;
21
      label?: string;
22
      permissions?: "read_only" | "read_write";
23
    }[];
24
    firewall?: {
25
      id?: number;
26
      label?: string;
27
      permissions?: "read_only" | "read_write";
28
    }[];
29
    global?: {
30
      account_access?: "read_only" | "read_write";
31
      add_databases?: false | true;
32
      add_domains?: false | true;
33
      add_firewalls?: false | true;
34
      add_images?: false | true;
35
      add_linodes?: false | true;
36
      add_longview?: false | true;
37
      add_nodebalancers?: false | true;
38
      add_stackscripts?: false | true;
39
      add_volumes?: false | true;
40
      add_vpcs?: false | true;
41
      cancel_account?: false | true;
42
      child_account_access?: false | true;
43
      longview_subscription?: false | true;
44
    };
45
    image?: {
46
      id?: number;
47
      label?: string;
48
      permissions?: "read_only" | "read_write";
49
    }[];
50
    linode?: {
51
      id?: number;
52
      label?: string;
53
      permissions?: "read_only" | "read_write";
54
    }[];
55
    longview?: {
56
      id?: number;
57
      label?: string;
58
      permissions?: "read_only" | "read_write";
59
    }[];
60
    nodebalancer?: {
61
      id?: number;
62
      label?: string;
63
      permissions?: "read_only" | "read_write";
64
    }[];
65
    stackscript?: {
66
      id?: number;
67
      label?: string;
68
      permissions?: "read_only" | "read_write";
69
    }[];
70
    volume?: {
71
      id?: number;
72
      label?: string;
73
      permissions?: "read_only" | "read_write";
74
    }[];
75
    vpc?: {
76
      id?: number;
77
      label?: string;
78
      permissions?: "read_only" | "read_write";
79
    }[];
80
  },
81
) {
82
  const url = new URL(
83
    `https://api.linode.com/${apiVersion}/account/users/${username}/grants`,
84
  );
85

86
  const response = await fetch(url, {
87
    method: "PUT",
88
    headers: {
89
      "Content-Type": "application/json",
90
      Authorization: "Bearer " + auth.token,
91
    },
92
    body: JSON.stringify(body),
93
  });
94
  if (!response.ok) {
95
    const text = await response.text();
96
    throw new Error(`${response.status} ${text}`);
97
  }
98
  return await response.json();
99
}
100