-
Notifications
You must be signed in to change notification settings - Fork 26
UsageRecords
Branko Conjic edited this page Feb 8, 2024
·
2 revisions
Create a usage record.
import { type NewUsageRecord, type UsageRecord, createUsageRecord } from '@lemonsqueezy/lemonsqueezy.js';
const { statusCode, error, data } = await createUsageRecord({ quantity: 10, subscriptionItemId: 234567 });
/**
* 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 a usage record object.
{
statusCode: number | null;
error: Error | null;
data: UsageRecord | null;
}
Retrieves the usage record with the given ID.
import { type UsageRecord, getUsageRecord } from '@lemonsqueezy/lemonsqueezy.js';
const usageRecordId = 345678;
const { statusCode, error, data } = await getUsageRecord(usageRecordId);
With related resources:
import { type UsageRecord, type GetUsageRecordParams, getUsageRecord } from '@lemonsqueezy/lemonsqueezy.js';
const usageRecordId = 345678;
const { statusCode, error, data } = await getUsageRecord(usageRecordId, { include: ['subscription-item'] });
/**
* 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 a usage record object.
{
statusCode: number | null;
error: Error | null;
data: UsageRecord | null;
}
Returns a paginated list of usage records.
import { type ListUsageRecords, listSubscriptions } from '@lemonsqueezy/lemonsqueezy.js';
const { statusCode, error, data } = await listUsageRecords();
With filter:
import { type ListUsageRecords, type ListUsageRecordsParams, listUsageRecords } from '@lemonsqueezy/lemonsqueezy.js';
const { statusCode, error, data } = await listUsageRecords({ filter: { subscriptionItemId: 345678 } });
With pagination:
import { type ListUsageRecords, type ListUsageRecordsParams, listUsageRecords } from '@lemonsqueezy/lemonsqueezy.js';
const { statusCode, error, data } = await listUsageRecords({ page: { number: 1, size: 10 } });
With related resources:
import { type ListUsageRecords, type ListUsageRecordsParams, listUsageRecords } from '@lemonsqueezy/lemonsqueezy.js';
const { statusCode, error, data } = await listUsageRecords({ include: ['subscription-item'] });
/**
* 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 a paginated list of usage record objects ordered by created_at
(descending).
{
statusCode: number | null;
error: Error | null;
data: ListUsageRecords | null;
}