-
Notifications
You must be signed in to change notification settings - Fork 26
Customers
Branko Conjic edited this page Feb 4, 2024
·
1 revision
Create a customer.
import { type NewCustomer, type Customer, createCustomer } from '@lemonsqueezy/lemonsqueezy.js';
const storeId = 123456;
const newCustomer: NewCustomer = { name: 'test', email: '[email protected]' };
const { statusCode, error, data } = await createCustomer(storeId, newCustomer);
/**
* Create a customer.
*
* @param storeId (Required)The Store ID.
* @param customer (Required) The new customer information.
* @param customer.name (Required) The name of the customer.
* @param customer.email (Required) The email of the customer.
* @param customer.city (Optional) The city of the customer.
* @param customer.region (Optional) The region of the customer.
* @param customer.country (Optional) The [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) two-letter country code for the customer (e.g. `US`, `GB`, etc).
* @returns A customer object.
*/
declare function createCustomer(storeId: number | string, customer: NewCustomer): Promise<FetchResponse<Customer>>;
Returns a customer object.
{
statusCode: number | null;
error: Error | null;
data: Customer | null;
}
Update a customer.
import { type UpdateCustomer, Type Customer, updateCustomer } from '@lemonsqueezy/lemonsqueezy.js'
const customerId = 456789
const customer: UpdateCustomer = { name: 'newTest', email: '[email protected]', country: 'AG', region: 'SG' }
const { statusCode, error, data } = await updateCustomer(customerId, customer)
/**
* Update a customer.
*
* @param customerId The customer id.
* @param customer The customer information that needs to be updated.
* @param customer.name (Optional) The name of the customer.
* @param customer.email (Optional) The email of the customer.
* @param customer.city (Optional) The city of the customer.
* @param customer.region (Optional) The region of the customer.
* @param customer.country (Optional) The [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) two-letter country code for the customer (e.g. `US`, `GB`, etc).
* @param customer.status (Optional) The email marketing status of the customer. Only one value: `archived`.
* @returns A customer object.
*/
declare function updateCustomer(customerId: string | number, customer: UpdateCustomer): Promise<FetchResponse<Customer>>;
Returns a customers object.
{
statusCode: number | null;
error: Error | null;
data: Customer | null;
}
Archive a customer.
import { type Customer, archiveCustomer } from '@lemonsqueezy/lemonsqueezy.js';
const customerId = 456789;
const { statusCode, error, data } = await archiveCustomer(customerId);
You can also use the updateCustomer
function:
import { type Customer, type UpdateCustomer, updateCustomer } from '@lemonsqueezy/lemonsqueezy.js';
const customerId = 456789;
const { statusCode, error, data } = await updateCustomer(customerId, { status: 'archived' });
/**
* Archive a customer.
*
* @param customerId The customer id.
* @returns A customer object.
*/
declare function archiveCustomer(customerId: string | number): Promise<FetchResponse<Customer>>;
Returns a customers object.
{
statusCode: number | null;
error: Error | null;
data: Customer | null;
}
Retrieves the customer with the given ID.
import { type Customer, getCustomer } from '@lemonsqueezy/lemonsqueezy.js';
const customerId = 456789;
const { statusCode, error, data } = await getCustomer(customerId);
With related resources:
import { type Customer, type GetCustomerParams, getCustomer } from '@lemonsqueezy/lemonsqueezy.js';
const customerId = 456789;
const { statusCode, error, data } = await getCustomer(customerId, { include: ['orders'] });
/**
* Retrieve a customer.
*
* @param customerId The given customer id.
* @param [params] (Optional) Additional parameters.
* @param [params.include] (Optional) Related resources.
* @returns A customer object.
*/
declare function getCustomer(customerId: string | number, params?: GetCustomerParams): Promise<FetchResponse<Customer>>;
Returns a customer object.
{
statusCode: number | null;
error: Error | null;
data: Customer | null;
}
Returns a paginated list of customers.
import { type ListCustomers, listCustomers } from '@lemonsqueezy/lemonsqueezy.js';
const { statusCode, error, data } = await listCustomers();
With filter:
import { type ListCustomers, type ListCustomersParams, listCustomers } from '@lemonsqueezy/lemonsqueezy.js';
const { statusCode, error, data } = await listCustomers({ filter: { storeId: 123456 } });
With pagination:
import { type ListCustomers, type ListCustomersParams, listCustomers } from '@lemonsqueezy/lemonsqueezy.js';
const { statusCode, error, data } = await listCustomers({ page: { number: 1, size: 10 } });
With related resource:
import { type ListCustomers, type ListCustomersParams, listCustomers } from '@lemonsqueezy/lemonsqueezy.js';
const { statusCode, error, data } = await listCustomers({ include: ['store'] });
/**
* List all customers.
*
* @param [params] (Optional) Additional parameters.
* @param [params.filter] (Optional) Filter parameters.
* @param [params.filter.storeId] (Optional) Only return customers belonging to the store with this ID.
* @param [params.filter.email] (Optional) Only return customers where the email field is equal to this email address.
* @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 customer objects ordered by `created_at` (descending).
*/
declare function listCustomers(params?: ListCustomersParams): Promise<FetchResponse<ListCustomers>>;
Returns a paginated list of customer objects ordered by created_at
(descending).
{
statusCode: number | null;
error: Error | null;
data: ListCustomers | null;
}