Skip to content

Commit

Permalink
feat: support webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
UnderKoen committed Jan 15, 2025
1 parent b258866 commit b203921
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- Custom Fields
- Ledger accounts*
- Workflows
- Webhooks

*not all endpoints are yet implemented

Expand Down
20 changes: 20 additions & 0 deletions src/administration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
ISalesInvoiceState,
ITax,
ITaxRateType,
IWebhook,
IWebhookCreate,
IWorkflow,
} from "./common";
import { Contact } from "./contact";
Expand Down Expand Up @@ -349,4 +351,22 @@ export class Administration {
}

//endregion Workflows

////////////////////////// WEBHOOKS /////////////////////////
//region Webhooks

public async webhooks(params?: PaginatedOptions): Promise<IWebhook[]> {
return await this.HTTP.GET<IWebhook[]>("webhooks", { params });
}

public async createWebhook(webhook: IWebhookCreate): Promise<IWebhook> {
return await this.HTTP.POST<IWebhook>("webhooks", { webhook });
}

public async deleteWebhook(webhook: string | IWebhook): Promise<void> {
const id = typeof webhook === "string" ? webhook : webhook.id;
await this.HTTP.DELETE(`webhooks/${id}`);
}

//endregion Webhooks
}
18 changes: 18 additions & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
}

0 comments on commit b203921

Please sign in to comment.