Skip to content

Discounts

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

createDiscount

Create a discount.

Usage

import { type NewDiscount, type Discount, createDiscount } from '@lemonsqueezy/lemonsqueezy.js';

const { statusCode, error, data } = await createDiscount({
	name: 'TestDiscount',
	amount: 50,
	amountType: 'percent',
	storeId: 123456,
	variantIds: [345678, 456789],
});

Type Declarations

/**
 * Create a discount.
 *
 * @param discount New discount info.
 * @returns A discount object.
 */
declare function createDiscount(discount: NewDiscount): Promise<FetchResponse<Discount>>;

Returns

Returns a discount object.

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

Source

Source ~ Type ~ Test

deleteDiscount

Delete a discount with the given ID.

Usage

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

const discountId = 677889;
const { statusCode, error, data } = await deleteDiscount(discountId);

Type Declarations

/**
 * Delete a discount.
 *
 * @param discountId The given discount id.
 * @returns A `204 No Content` response on success.
 */
declare function deleteDiscount(discountId: string | number): 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

getDiscount

Retrieves the discount with the given ID.

Usage

import { type Discount, getDiscount } from '@lemonsqueezy/lemonsqueezy.js';

const discountId = 677889;
const { statusCode, error, data } = await getDiscount(discountId);

With related resources:

import { type Discount, type GetDiscountParams, getDiscount } from '@lemonsqueezy/lemonsqueezy.js';

const discountId = 677889;
const { statusCode, error, data } = await getDiscount(discountId, { include: ['store'] });

Type Declarations

/**
 * Retrieve a discount.
 *
 * @param discountId The given discount id.
 * @param [params] (Optional) Additional parameters.
 * @param [params.include] (Optional) Related resources.
 * @returns A discount object.
 */
declare function getDiscount(discountId: number | string, params?: GetDiscountParams): Promise<FetchResponse<Discount>>;

Returns

Returns a discount object.

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

Source

Source ~ Type ~ Test

listDiscounts

Returns a paginated list of discounts.

Usage

import { type ListDiscounts, listDiscounts } from '@lemonsqueezy/lemonsqueezy.js';

const { statusCode, error, data } = await listDiscounts();

With filter:

import { type ListDiscounts, type ListDiscountsParams, listDiscounts } from '@lemonsqueezy/lemonsqueezy.js';

const { statusCode, error, data } = await listDiscounts({ filter: { storeId: 123456 } });

With pagination:

import { type ListDiscounts, type ListDiscountsParams, listDiscounts } from '@lemonsqueezy/lemonsqueezy.js';

const { statusCode, error, data } = await listDiscounts({ page: { number: 1, size: 10 } });

With related resources:

import { type ListDiscounts, type ListDiscountsParams, listDiscounts } from '@lemonsqueezy/lemonsqueezy.js';

const { statusCode, error, data } = await listDiscounts({ include: ['store'] });

Type Declarations

/**
 * List all discounts.
 *
 * @param [params] (Optional) Additional parameters.
 * @param [params.filter] (Optional) Filter parameters.
 * @param [params.filter.storeId] (Optional) Only return discounts 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 discount objects ordered by `created_at`.
 */
declare function listDiscounts(params?: ListDiscountsParams): Promise<FetchResponse<ListDiscounts>>;

Returns

Returns a paginated list of discount objects ordered by created_at.

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

Source

Source ~ Type ~ Test

Clone this wiki locally