Setup dev printful/webflow webhooks

This commit is contained in:
Dominic Ferrando
2026-06-26 13:44:19 -04:00
parent a689417aed
commit 62b651c476
5 changed files with 58 additions and 1 deletions
+35
View File
@@ -121,9 +121,43 @@ class OrdersClient {
}
}
class WebhooksClient {
constructor(private creds: Credentials) { }
async getConfig(): Promise<Printful.Webhook.Config | undefined> {
const res = await fetch(`${this.creds.apiUrl}/webhooks`, {
method: "GET",
headers: {
"Content-Type": "application/json",
...this.creds.authHeaders,
}
});
if (res.status === 404 || res.status === 400) return;
if (!res.ok) throw new PrintfulError("Failed to get webhook configuration", res.status, await parsePayload(res));
const payload = (await res.json()) as Printful.Webhook.Config;
return payload;
}
async register(url: string, events: Printful.Webhook.Event[]) {
const res = await fetch(`${this.creds.apiUrl}/webhooks`, {
method: "POST",
headers: {
"Content-Type": "application/json",
...this.creds.authHeaders,
},
body: JSON.stringify({
"url": url,
"types": events
}),
});
if (!res.ok) throw new PrintfulError("Failed to register webhook URL", res.status, await parsePayload(res));
}
}
export class PrintfulClient {
readonly Products: ProductsClient;
readonly Orders: OrdersClient;
readonly Webhooks: WebhooksClient;
constructor(options: ClientOptions) {
const creds: Credentials = {
@@ -135,6 +169,7 @@ export class PrintfulClient {
};
this.Products = new ProductsClient(creds);
this.Orders = new OrdersClient(creds);
this.Webhooks = new WebhooksClient(creds);
}
static Util = {
+5
View File
@@ -133,6 +133,11 @@ export namespace Printful {
PackageShipped = "package_shipped",
}
export interface Config {
url: string,
types: Event[]
}
export interface ProductUpdated extends MetaData<
Event.ProductUpdated,
{