0

Create jobs to terminate users session

by
Published Oct 17, 2025

Validates the roles and permissions of the user, and creates asynchronous jobs to terminate the user's sessions. Returns the status for the POST request.

Script box Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Box = {
3
  token: string;
4
};
5
/**
6
 * Create jobs to terminate users session
7
 * Validates the roles and permissions of the user,
8
and creates asynchronous jobs
9
to terminate the user's sessions.
10
Returns the status for the POST request.
11
 */
12
export async function main(
13
  auth: Box,
14
  body: { user_ids: string[]; user_logins: string[] },
15
) {
16
  const url = new URL(`https://api.box.com/2.0/users/terminate_sessions`);
17

18
  const response = await fetch(url, {
19
    method: "POST",
20
    headers: {
21
      "Content-Type": "application/json",
22
      Authorization: "Bearer " + auth.token,
23
    },
24
    body: JSON.stringify(body),
25
  });
26
  if (!response.ok) {
27
    const text = await response.text();
28
    throw new Error(`${response.status} ${text}`);
29
  }
30
  return await response.json();
31
}
32