Repository navigation
Webhooks
Branko Conjic edited this page Feb 8, 2024
·
2 revisions
Create a webhook.
import { type NewWebhook, type Webhook, createWebhook } from '@lemonsqueezy/lemonsqueezy.js';
const storeId = 123456;
const { statusCode, error, data } = await createWebhook(storeId, {
url: 'https://google.com/webhooks',
events: ['subscription_created', 'subscription_cancelled'],
secret: 'SUBSCRIPTION_SECRET',
});/**
* Create a webhook.
*
* @param storeId The store id.
* @param webhook a new webhook info.
* @returns A webhook object.
*/
declare function createWebhook(storeId: number | string, webhook: NewWebhook): Promise<FetchResponse<Webhook>>;Returns a webhook object.
{
statusCode: number | null;
error: Error | null;
data: Webhook | null;
}Update a webhook.
import { type UpdateWebhook, type Webhook, updateWebhook } from '@lemonsqueezy/lemonsqueezy.js';
const webhookId = 456789;
const { statusCode, error, data } = await updateWebhook(webhookId, { url: 'https://google.com/webhooks2' });/**
* Update a webhook.
*
* @param webhookId The webhook id.
* @param webhook The webhook info you want to update.
* @returns A webhook object.
*/
declare function updateWebhook(webhookId: number | string, webhook: UpdateWebhook): Promise<FetchResponse<Webhook>>;Returns a webhook object.
{
statusCode: number | null;
error: Error | null;
data: Webhook | null;
}Delete a webhook with the given ID.
import { deleteWebhook } from '@lemonsqueezy/lemonsqueezy.js';
const webhookId = 456789;
const { statusCode, error, data } = await deleteWebhook(webhookId);/**
* Delete a webhook.
*
* @param webhookId The webhook id.
* @returns A `204` status code and `No Content` response on success.
*/
declare function deleteWebhook(webhookId: number | string): Promise<FetchResponse<null>>;Returns a status code 204 and No Content response on success.
{
statusCode: number | null;
error: Error | null;
data: null;
}Retrieves the webhook with the given ID.
import { type Webhook, getWebhook } from '@lemonsqueezy/lemonsqueezy.js';
const { statusCode, error, data } = await getWebhook();With related resources:
import { type Webhook, type GetWebhookParams, getWebhook } from '@lemonsqueezy/lemonsqueezy.js';
const { statusCode, error, data } = await getWebhook({ include: ['store'] });/**
* Retrieve a webhook.
*
* @param webhookId The given webhook id.
* @param [params] (Optional) Additional parameters.
* @param [params.include] (Optional) Related resources.
* @returns A webhook object.
*/
declare function getWebhook(webhookId: number | string, params?: GetWebhookParams): Promise<FetchResponse<Webhook>>;Returns a webhook object.
{
statusCode: number | null;
error: Error | null;
data: Webhook | null;
}Returns a paginated list of webhooks.
import { type ListWebhooks, listWebhooks } from '@lemonsqueezy/lemonsqueezy.js';
const { statusCode, error, data } = await listWebhooks();With filter:
import { type ListWebhooks, type ListWebhooksParams, listWebhooks } from '@lemonsqueezy/lemonsqueezy.js';
const { statusCode, error, data } = await listWebhooks({ filter: { storeId: 123456 } });With pagination:
import { type ListWebhooks, type ListWebhooksParams, listWebhooks } from '@lemonsqueezy/lemonsqueezy.js';
const { statusCode, error, data } = await listWebhooks({ page: { number: 1, size: 10 } });With related resources:
import { type ListWebhooks, type ListWebhooksParams, listWebhooks } from '@lemonsqueezy/lemonsqueezy.js';
const { statusCode, error, data } = await listWebhooks({ include: ['store'] });/**
* List all webhooks.
*
* @param [params] (Optional) Additional parameters.
* @param [params.filter] (Optional) Filter parameters.
* @param [params.filter.storeId] (Optional) Only return webhooks belonging to the store with this ID.
* @param [params.page] (Optional) Custom paginated queries.
* @param [params.page.number] (Optional) The parameter determine which page to retrieve.
* @param [params.page.size] (Optional) The parameter to determine how many results to return per page.
* @param [params.include] (Optional) Related resources.
* @returns A paginated list of webhook objects ordered by `created_at`.
*/
declare function listWebhooks(params?: ListWebhooksParams): Promise<FetchResponse<ListWebhooks>>;Returns a paginated list of subscription objects ordered by created_at (descending).
{
statusCode: number | null;
error: Error | null;
data: ListWebhooks | null;
}