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

UsageRecords

Caven edited this page Jan 31, 2024 · 1 revision

createUsageRecord

Create a usage record.

Usage

import { type NewUsageRecord, type UsageRecord, createUsageRecord } from '@heybrostudio/lemonsqueezy.js'

const { statusCode, error, data } = await createUsageRecord({ quantity: 10, subscriptionItemId: 234567 })

Type Declarations

/**
 * Create a usage record.
 *
 * @param usageRecord (Required) New usage record info.
 * @param usageRecord.quantity (Required) A positive integer representing the usage to be reported.
 * @param usageRecord.action (Optional) The type of record. `increment` or `set`. Defaults to `increment` if omitted.
 * @param usageRecord.subscriptionItemId (Required) The subscription item this usage record belongs to.
 * @returns A usage record object.
 */
declare function createUsageRecord(usageRecord: NewUsageRecord): Promise<FetchResponse<UsageRecord>>

Returns

Returns a usage record object.

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

Source

Source ~ Type ~ Test

getUsageRecord

Retrieves the usage record with the given ID.

Usage

import { type UsageRecord, getUsageRecord } from '@heybrostudio/lemonsqueezy.js'

const usageRecordId = 345678
const { statusCode, error, data } = await getUsageRecord(usageRecordId)

With related resources:

import { type UsageRecord, type GetUsageRecordParams, getUsageRecord } from '@heybrostudio/lemonsqueezy.js'

const usageRecordId = 345678
const { statusCode, error, data } = await getUsageRecord(usageRecordId, { include: ['subscription-item'] })

Type Declarations

/**
 * Retrieve a usage record.
 *
 * @param usageRecordId The usage record id.
 * @param [params] (Optional) Additional parameters.
 * @param [params.include] (Optional) Related resources.
 * @returns A usage record object.
 */
declare function getUsageRecord(
  usageRecordId: number | string,
  params?: GetUsageRecordParams,
): Promise<FetchResponse<UsageRecord>>

Returns

Returns a usage record object.

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

Source

Source ~ Type ~ Test

listUsageRecords

Returns a paginated list of usage records.

Usage

import { type ListUsageRecords, listSubscriptions } from '@heybrostudio/lemonsqueezy.js'

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

With filter:

import { type ListUsageRecords, type ListUsageRecordsParams, listUsageRecords } from '@heybrostudio/lemonsqueezy.js'

const { statusCode, error, data } = await listUsageRecords({ filter: { subscriptionItemId: 345678 } })

With pagination:

import { type ListUsageRecords, type ListUsageRecordsParams, listUsageRecords } from '@heybrostudio/lemonsqueezy.js'

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

With related resources:

import { type ListUsageRecords, type ListUsageRecordsParams, listUsageRecords } from '@heybrostudio/lemonsqueezy.js'

const { statusCode, error, data } = await listUsageRecords({ include: ['subscription-item'] })

Type Declarations

/**
 * List all usage records.
 *
 * @param [params] (Optional) Additional parameters.
 * @param [params.filter] (Optional) Filter parameters.
 * @param [params.filter.subscriptionItemId] (Optional) Only return usage records belonging to the subscription item 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 usage record objects ordered by `created_at` (descending).
 */
declare function listUsageRecords(params?: ListUsageRecordsParams): Promise<FetchResponse<ListUsageRecords>>

Returns

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

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

Source

Source ~ Type ~ Test

Clone this wiki locally