type Trello = {
key: string;
token: string;
};
/**
* Create Webhooks for Token
* Create a new webhook for a Token.
*/
export async function main(
auth: Trello,
token: string,
description: string | undefined,
callbackURL: string | undefined,
idModel: string | undefined
) {
const url = new URL(`https://api.trello.com/1/tokens/${token}/webhooks`);
for (const [k, v] of [
["description", description],
["callbackURL", callbackURL],
["idModel", idModel],
["key", auth.key],
["token", auth.token],
]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: undefined,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 51 days ago
type Trello = {
key: string;
token: string;
};
/**
* Create Webhooks for Token
* Create a new webhook for a Token.
*/
export async function main(
auth: Trello,
token: string,
description: string | undefined,
callbackURL: string | undefined,
idModel: string | undefined
) {
const url = new URL(`https://api.trello.com/1/tokens/${token}/webhooks`);
for (const [k, v] of [
["description", description],
["callbackURL", callbackURL],
["idModel", idModel],
["key", auth.key],
["token", auth.token],
]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: undefined,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 606 days ago