From b203921c44d16cff8942ca45e29f23d18dc043e1 Mon Sep 17 00:00:00 2001 From: UnderKoen Date: Wed, 15 Jan 2025 15:01:45 +0100 Subject: [PATCH] feat: support webhooks --- README.md | 1 + src/administration.ts | 20 ++++++++++++++++++++ src/common.ts | 18 ++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/README.md b/README.md index e2b52a3..a72a812 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ - Custom Fields - Ledger accounts* - Workflows +- Webhooks *not all endpoints are yet implemented diff --git a/src/administration.ts b/src/administration.ts index ca0e77b..2ceea16 100644 --- a/src/administration.ts +++ b/src/administration.ts @@ -10,6 +10,8 @@ import { ISalesInvoiceState, ITax, ITaxRateType, + IWebhook, + IWebhookCreate, IWorkflow, } from "./common"; import { Contact } from "./contact"; @@ -349,4 +351,22 @@ export class Administration { } //endregion Workflows + + ////////////////////////// WEBHOOKS ///////////////////////// + //region Webhooks + + public async webhooks(params?: PaginatedOptions): Promise { + return await this.HTTP.GET("webhooks", { params }); + } + + public async createWebhook(webhook: IWebhookCreate): Promise { + return await this.HTTP.POST("webhooks", { webhook }); + } + + public async deleteWebhook(webhook: string | IWebhook): Promise { + const id = typeof webhook === "string" ? webhook : webhook.id; + await this.HTTP.DELETE(`webhooks/${id}`); + } + + //endregion Webhooks } diff --git a/src/common.ts b/src/common.ts index a2fba23..717dee1 100644 --- a/src/common.ts +++ b/src/common.ts @@ -384,3 +384,21 @@ export interface IWorkflow { created_at: string; updated_at: string; } + +export interface IWebhook { + id: string; + administration_id: string; + url: string; + enabled_events: string[]; + last_http_status: number | null; + last_http_response: unknown | null; + token: string; +} + +export interface IWebhookCreate { + url: string; + /** + * For available events, see https://developer.moneybird.com/webhooks/#events + */ + enabled_events?: string[]; +}