//native
type Attio = {
token: string;
};
/**
* Create a webhook
* Create a webhook and associated subscriptions.
Required scopes: `webhook:read-write`.
*/
export async function main(
auth: Attio,
body: {
data: {
target_url: string;
subscriptions: {
event_type:
| "comment.created"
| "comment.resolved"
| "comment.unresolved"
| "comment.deleted"
| "list.created"
| "list.updated"
| "list.deleted"
| "list-attribute.created"
| "list-attribute.updated"
| "list-entry.created"
| "list-entry.updated"
| "list-entry.deleted"
| "object-attribute.created"
| "object-attribute.updated"
| "note.created"
| "note.updated"
| "note.deleted"
| "record.created"
| "record.merged"
| "record.updated"
| "record.deleted"
| "task.created"
| "task.updated"
| "task.deleted"
| "workspace-member.created";
filter:
| {
$or:
| { field: string; operator: "equals"; value: string }
| { field: string; operator: "not_equals"; value: string }[];
}
| {
$and:
| { field: string; operator: "equals"; value: string }
| { field: string; operator: "not_equals"; value: string }[];
};
}[];
};
},
) {
const url = new URL(`https://api.attio.com/v2/webhooks`);
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 51 days ago