Improve webhook client api and make script to register webhooks
This commit is contained in:
@@ -55,7 +55,7 @@ class ProductsClient {
|
||||
method: "GET",
|
||||
headers: this.creds.authHeaders,
|
||||
});
|
||||
if (!res.ok) throw new PrintfulError("Failed to get all Printful products", res.status, await parsePayload(res));
|
||||
if (!res.ok) throw new PrintfulError("Failed to list Printful products", res.status, await parsePayload(res));
|
||||
const payload = (await res.json()) as Printful.MetaDataMulti<Printful.Products.SyncProduct>;
|
||||
allSyncProducts.push(...payload.result);
|
||||
offset = allSyncProducts.length;
|
||||
@@ -111,7 +111,7 @@ class OrdersClient {
|
||||
method: "GET",
|
||||
headers: this.creds.authHeaders,
|
||||
});
|
||||
if (!res.ok) throw new PrintfulError("Failed to get all Printful orders", res.status, await parsePayload(res));
|
||||
if (!res.ok) throw new PrintfulError("Failed to list Printful orders", res.status, await parsePayload(res));
|
||||
const payload = (await res.json()) as Printful.MetaDataMulti<Printful.Orders.Order>;
|
||||
allPrintfulOrders.push(...payload.result);
|
||||
offset = allPrintfulOrders.length;
|
||||
@@ -124,7 +124,7 @@ class OrdersClient {
|
||||
class WebhooksClient {
|
||||
constructor(private creds: Credentials) { }
|
||||
|
||||
async getConfig(): Promise<Printful.Webhook.Config | undefined> {
|
||||
async get(): Promise<Printful.Webhook.Config | undefined> {
|
||||
const res = await fetch(`${this.creds.apiUrl}/webhooks`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
@@ -138,7 +138,11 @@ class WebhooksClient {
|
||||
return payload;
|
||||
}
|
||||
|
||||
async register(url: string, events: Printful.Webhook.Event[]) {
|
||||
|
||||
/**
|
||||
* Printful only supports one URL at a time, so subsequent calls will overwrite the previous webhook
|
||||
*/
|
||||
async create(url: string, events: Printful.Webhook.Event[]) {
|
||||
const res = await fetch(`${this.creds.apiUrl}/webhooks`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
||||
Reference in New Issue
Block a user