//native
type Smartsheet = {
token: string;
baseUrl: string;
};
/**
* Add User
* Adds a user to the organization account.
*/
export async function main(
auth: Smartsheet,
sendEmail: string | undefined,
body: {
id?: number;
admin?: false | true;
customWelcomeScreenViewed?: string;
email?: string;
firstName?: string;
groupAdmin?: false | true;
lastLogin?: string;
lastName?: string;
licensedSheetCreator?: false | true;
name?: string;
profileImage?: { imageId?: string; height?: string; width?: string };
resourceViewer?: false | true;
sheetCount?: number;
status?: "ACTIVE" | "DECLINED" | "PENDING" | "DEACTIVATED";
},
) {
const url = new URL(`${auth.baseUrl}/users`);
for (const [k, v] of [["sendEmail", sendEmail]]) {
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