//native
type Box = {
token: string;
};
/**
* Create user invite
* Invites an existing external user to join an enterprise.
The existing user can not be part of another enterprise and
must already have a Box account. Once invited, the user will receive an
email and are prompted to accept the invitation within the
Box web application.
This method requires the "Manage An Enterprise" scope enabled for
the application, which can be enabled within the developer console.
*/
export async function main(
auth: Box,
fields: string | undefined,
body: { enterprise: { id: string }; actionable_by: { login?: string } },
) {
const url = new URL(`https://api.box.com/2.0/invites`);
for (const [k, v] of [["fields", fields]]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago