//native
type Box = {
token: string;
};
/**
* List enterprise users
* Returns a list of all users for the Enterprise along with their `user_id`,
`public_name`, and `login`.
The application and the authenticated user need to
have the permission to look up users in the entire
enterprise.
*/
export async function main(
auth: Box,
filter_term: string | undefined,
user_type: "all" | "managed" | "external" | undefined,
external_app_user_id: string | undefined,
fields: string | undefined,
offset: string | undefined,
limit: string | undefined,
usemarker: string | undefined,
marker: string | undefined,
) {
const url = new URL(`https://api.box.com/2.0/users`);
for (const [k, v] of [
["filter_term", filter_term],
["user_type", user_type],
["external_app_user_id", external_app_user_id],
["fields", fields],
["offset", offset],
["limit", limit],
["usemarker", usemarker],
["marker", marker],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago