Skip to content
This repository has been archived by the owner on Feb 4, 2024. It is now read-only.

Variants

Caven edited this page Jan 31, 2024 · 1 revision

getVariant

Retrieves the variant with the given ID.

Usage

import { type Variant, getVariant } from '@heybrostudio/lemonsqueezy.js'

const variantId = 234567
const { statusCode, error, data } = await getVariant(variantId)

With related resources:

import { type GetVariantParams, type Variant, getVariant } from '@heybrostudio/lemonsqueezy.js'

const variantId = 234567
const { statusCode, error, data } = await getVariant(variantId, { include: ['product'] })

Type Declarations

/**
 * Retrieve a variant.
 *
 * @param variantId The given variant id.
 * @param [params] (Optional) Additional parameters.
 * @param [params.include] (Optional) Related resources.
 * @returns A variant object.
 */
declare function getVariant(variantId: number | string, params?: GetVariantParams): Promise<FetchResponse<Variant>>

Returns

Returns a variant object.

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

Source

Source ~ Type ~ Test

listVariants

Returns a paginated list of variants.

Usage

import { type ListVariants, listVariants } from '@heybrostudio/lemonsqueezy.js'

const { statusCode, error, data } = await listVariants()

With filter:

import { type ListVariants, type ListVariantsParams, listVariants } from '@heybrostudio/lemonsqueezy.js'

const { statusCode, error, data } = await listVariants({ filter: { productId: 234567 } })

With pagination:

import { type ListVariants, type ListVariantsParams, listVariants } from '@heybrostudio/lemonsqueezy.js'

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

With related resources:

import { type ListVariants, type ListVariantsParams, listVariants } from '@heybrostudio/lemonsqueezy.js'

const { statusCode, error, data } = await listVariants({ include: ['product'] })

Type Declarations

/**
 * List all variants
 *
 * @param [params] (Optional) Additional parameters.
 * @param [params.filter] (Optional) Filter parameters.
 * @param [params.filter.productId] (Optional) Only return variants belonging to the product with this ID.
 * @param [params.filter.status] (Optional) Only return variants with this status.
 * @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 variant objects ordered by `sort`.
 */
declare function listVariants(params?: ListVariantsParams): Promise<FetchResponse<ListVariants>>

Returns

Returns a paginated list of variant objects ordered by sort.

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

Source

Source ~ Type ~ Test

Clone this wiki locally