Skip to content

Webhooks

Branko Conjic edited this page Feb 8, 2024 · 2 revisions

createWebhook

Create a webhook.

Usage

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',
});

Type Declarations

/**
 * 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

Returns a webhook object.

{
	statusCode: number | null;
	error: Error | null;
	data: Webhook | null;
}

Source

Source ~ Type ~ Test

updateWebhook

Update a webhook.

Usage

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' });

Type Declarations

/**
 * 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

Returns a webhook object.

{
	statusCode: number | null;
	error: Error | null;
	data: Webhook | null;
}

Source

Source ~ Type ~ Test

deleteWebhook

Delete a webhook with the given ID.

Usage

import { deleteWebhook } from '@lemonsqueezy/lemonsqueezy.js';

const webhookId = 456789;
const { statusCode, error, data } = await deleteWebhook(webhookId);

Type Declarations

/**
 * 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

Returns a status code 204 and No Content response on success.

{
	statusCode: number | null;
	error: Error | null;
	data: null;
}

Source

Source ~ Test

getWebhook

Retrieves the webhook with the given ID.

Usage

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'] });

Type Declarations

/**
 * 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

Returns a webhook object.

{
	statusCode: number | null;
	error: Error | null;
	data: Webhook | null;
}

Source

Source ~ Type ~ Test

listWebhooks

Returns a paginated list of webhooks.

Usage

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'] });

Type Declarations

/**
 * 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

Returns a paginated list of subscription objects ordered by created_at (descending).

{
	statusCode: number | null;
	error: Error | null;
	data: ListWebhooks | null;
}

Source

Source ~ Type ~ Test