0

Add Permissions to User

by
Published Oct 17, 2025

Adds a list of access permissions to a user. • When called, this endpoint may generate one or more of the following audit trail events:* Policy Created * User Policy Updated The rate limit for this endpoint is 60 requests per minute, which is lower than the default due to access pattern restrictions. Once reached, this endpoint will respond with the 429 HTTP status code with headers indicating the limit parameters. See Rate Limiting for more information.

Script segment Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Segment = {
3
  token: string;
4
  baseUrl: string;
5
};
6
/**
7
 * Add Permissions to User
8
 * Adds a list of access permissions to a user.
9

10

11

12
• When called, this endpoint may generate one or more of the following audit trail events:* Policy Created
13
* User Policy Updated
14
      
15

16

17
The rate limit for this endpoint is 60 requests per minute, which is lower than the default due to access pattern restrictions. Once reached, this endpoint will respond with the 429 HTTP status code with headers indicating the limit parameters. See Rate Limiting for more information.
18
 */
19
export async function main(
20
  auth: Segment,
21
  userId: string,
22
  body: {
23
    permissions: {
24
      roleId: string;
25
      resources: {
26
        id: string;
27
        type: "FUNCTION" | "SOURCE" | "SPACE" | "WAREHOUSE" | "WORKSPACE";
28
        labels?: { key: string; value: string; description?: string }[];
29
      }[];
30
    }[];
31
  },
32
) {
33
  const url = new URL(
34
    `${auth.baseUrl}/users/${userId}/permissions`,
35
  );
36

37
  const response = await fetch(url, {
38
    method: "POST",
39
    headers: {
40
      "Content-Type": "application/json",
41
      Authorization: "Bearer " + auth.token,
42
    },
43
    body: JSON.stringify(body),
44
  });
45
  if (!response.ok) {
46
    const text = await response.text();
47
    throw new Error(`${response.status} ${text}`);
48
  }
49
  return await response.json();
50
}
51