//native
type Smartsheet = {
token: string;
baseUrl: string;
};
/**
* Add Group Members
* Adds one or more members to a group.
*/
export async function main(
auth: Smartsheet,
groupId: string,
body:
| {
id?: number;
email?: string;
firstName?: string;
lastName?: string;
name?: string;
}
| {
id?: number;
email?: string;
firstName?: string;
lastName?: string;
name?: string;
}[],
) {
const url = new URL(`${auth.baseUrl}/groups/${groupId}/members`);
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