Skip to main content

Products

Use the Product resource to manage your service or goods catalog. You can create, retrieve, and update products for use in Checkout Sessions, Payment Links, and related flows.

Accessing products​

All product operations are available via the client.product property on your GStableClient instance.

Error handling​

The SDK provides granular error handling for product operations. Business-specific errors (error codes 100301–100306) are captured and re-thrown as GStableProductError.

When a request fails, you can catch this error to branch on product-specific failures (for example, product not found or invalid status):

import { GStableClient, GStableProductError } from 'gstable-js';

const client = new GStableClient({ apiKey: process.env.GSTABLE_API_KEY! });

try {
const product = await client.product.create({
name: 'Gold Tier Plan',
commonPrices: [9_900_000],
});
} catch (error) {
if (error instanceof GStableProductError) {
console.error(`Product Error [${error.code}]: ${error.message}`);
}
}

TypeScript support​

We provide TypeScript definitions for product payloads and responses. Import them from the package root for type-safe calls.

Core types

  • Product — The main product object.
  • ProductStatus — Product availability (for example, active or archived).
  • ProductAttribute — Custom attributes (name + value) on a product.

Request bodies

  • CreateProductBody / UpdateProductBody — Schemas for creating or fully replacing a product.
  • ProductListByIdsBody — Batch retrieval by product id.

Response wrappers

  • ProductListData — Paginated list shape (total, page, size, products).
  • OperationSuccess — Returned for successful archive, unarchive, remove, and similar operations.
import type {
Product,
ProductStatus,
ProductAttribute,
CreateProductBody,
UpdateProductBody,
ProductListByIdsBody,
ProductListData,
OperationSuccess,
} from 'gstable-js';

create​

Creates a new catalog product.

client.product.create(body)

Parameters​

NameTypeRequiredDescription
bodyCreateProductBodyYesPayload sent as JSON.

CreateProductBody:

FieldTypeRequiredDescription
namestringYesDisplay name.
commonPricesnumber[]YesPrices in micro-USD (e.g. 1000000 = $1.00).
descriptionstringNoOptional description.
imageUrlstringNoOptional image URL.
attributesProductAttribute[]NoCustom attributes (name + value).

Returns​

Promise<Product> — Created product, including productId, status, etc.

Example​

import { GStableClient } from 'gstable-js';

const client = new GStableClient({ apiKey: process.env.GSTABLE_API_KEY! });
const product = await client.product.create({
name: 'Pro plan',
commonPrices: [9_900_000, 99_000_000], // $9.99 and $99.00 in micro-USD
description: 'Annual billing',
});
console.log(product.productId);

update​

Replaces a product with a full payload (API-defined “full replace” semantics).

client.product.update(body)

Parameters​

NameTypeRequiredDescription
bodyUpdateProductBodyYesMust include productId and all required fields.

UpdateProductBody:

FieldTypeRequiredDescription
productIdstringYesTarget product.
namestringYesNew name.
commonPricesnumber[]YesMicro-USD price list.
descriptionstringNoOptional.
imageUrlstringNoOptional.
attributesProductAttribute[]NoOptional.

Returns​

Promise<OperationSuccess> — { success: boolean } in data.

Example​

await client.product.update({
productId: 'prod_xxx',
name: 'Pro plan (updated)',
commonPrices: [10_000_000],
});

list​

Paginated product listing.

client.product.list(page, size)

Parameters​

NameTypeRequiredDescription
pagenumberYesPage index, starts at 1.
sizenumberYesPage size; maximum 100 (per SDK).

Returns​

Promise<ProductListData> — { total, page, size, products } (page / size are string in the type definition as returned by the API).

Example​

const { products, total } = await client.product.list(1, 50);
console.log(total, products.length);

listByIds​

Batch fetch by id; unknown ids are omitted (no error for missing ids).

client.product.listByIds(body)

Parameters​

NameTypeRequiredDescription
bodyProductListByIdsBodyYes{ productIds: string[] }.

Returns​

Promise<Product[]> — Only products that exist.

Example​

const rows = await client.product.listByIds({
productIds: ['prod_a', 'prod_b'],
});

archive​

client.product.archive(productId)

Parameters​

NameTypeRequiredDescription
productIdstringYesProduct to archive.

Returns​

Promise<OperationSuccess>

Example​

await client.product.archive('prod_xxx');

unarchive​

client.product.unarchive(productId)

Parameters​

NameTypeRequiredDescription
productIdstringYesProduct to restore from archived state.

Returns​

Promise<OperationSuccess>

Example​

await client.product.unarchive('prod_xxx');

remove​

Deletes a product only if it is not referenced by any Payment Link.

client.product.remove(productId)

Parameters​

NameTypeRequiredDescription
productIdstringYesProduct to delete.

Returns​

Promise<OperationSuccess>

Example​

await client.product.remove('prod_xxx');