UNPKG

shipstation-node

Version:
93 lines (92 loc) 2.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Webhooks = void 0; const BaseResource_1 = require("../../BaseResource"); /** * [Official Documentation](https://docs.shipstation.com/openapi/webhooks) * * Webhooks are a powerful feature that can save you from sending repeated polling requests to check on the state of * something. With webhooks, ShipStation will automatically contact your servers when the stage changes. This can * include parcel tracking events, notification when a batch operation completes, and more. */ class Webhooks extends BaseResource_1.BaseResource { constructor(shipstation) { super(shipstation, 'environment/webhooks'); } /** * [Official Documentation](https://docs.shipstation.com/openapi/webhooks/list_webhooks) * * List all webhooks currently enabled for the account. * * @returns A list of webhooks */ async list() { return this.shipstation.request({ url: this.baseUrl, method: 'GET' }); } /** * [Official Documentation](https://docs.shipstation.com/openapi/webhooks/create_webhook) * * Create a new webhook. * * @param data The data for the new webhook * * @returns The newly created webhook */ async create(data) { return this.shipstation.request({ url: this.baseUrl, method: 'POST', data }); } /** * [Official Documentation](https://docs.shipstation.com/openapi/webhooks/get_webhook_by_id) * * Retrieve individual webhook by an ID * * @param webhookId Webhook ID [1-25] characters `^se(-[a-z0-9]+)+$` * @example "se-28529731" * * @returns The webhook specified by the ID */ async getById(webhookId) { return this.shipstation.request({ url: `${this.baseUrl}/${webhookId}`, method: 'GET' }); } /** * [Official Documentation](https://docs.shipstation.com/openapi/webhooks/update_webhook) * * Update the webhook url property * * @param webhookId Webhook ID [1-25] characters `^se(-[a-z0-9]+)+$` * @example "se-28529731" * * @param data The data for updating the webhook */ async update(webhookId, data) { await this.shipstation.request({ url: `${this.baseUrl}/${webhookId}`, method: 'PUT', data }); } /** * [Official Documentation](https://docs.shipstation.com/openapi/webhooks/delete_webhook) * * Delete a webhook. * * @param webhookId Webhook ID [1-25] characters `^se(-[a-z0-9]+)+$` */ async deleteById(webhookId) { await this.shipstation.request({ url: `${this.baseUrl}/${webhookId}`, method: 'DELETE' }); } } exports.Webhooks = Webhooks;