type Trello = {
key: string;
token: string;
};
/**
* Invite Member to Board via email
* Invite a Member to a Board via their email address.
*/
export async function main(
auth: Trello,
id: string,
email: string | undefined,
type: "admin" | "normal" | "observer" | undefined,
body: { fullName?: string; [k: string]: unknown }
) {
const url = new URL(`https://api.trello.com/1/boards/${id}/members`);
for (const [k, v] of [
["email", email],
["type", type],
["key", auth.key],
["token", auth.token],
]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: undefined,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.text();
}
Submitted by hugo697 398 days ago
type Trello = {
key: string;
token: string;
};
/**
* Invite Member to Board via email
* Invite a Member to a Board via their email address.
*/
export async function main(
auth: Trello,
id: string,
email: string | undefined,
type: "admin" | "normal" | "observer" | undefined,
body: { fullName?: string; [k: string]: unknown }
) {
const url = new URL(`https://api.trello.com/1/boards/${id}/members`);
for (const [k, v] of [
["email", email],
["type", type],
["key", auth.key],
["token", auth.token],
]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: undefined,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.text();
}
Submitted by hugo697 953 days ago