CommerceSDK Reference
Admin Module
Complete reference for the @hanzo/sdk admin module -- manage products, orders, customers, and more
The Admin module provides full management access to your Hanzo Commerce store. It requires a secret API key and should only be used in server-side code or the admin dashboard.
Available Sub-Modules
| Module | Description |
|---|---|
sdk.admin.product | Products, variants, and options |
sdk.admin.order | Order lifecycle management |
sdk.admin.cart | Server-side cart management |
sdk.admin.customer | Customer profiles and addresses |
sdk.admin.payment | Payment capture, refund, and providers |
sdk.admin.fulfillment | Shipments and tracking |
sdk.admin.inventory | Stock levels and adjustments |
sdk.admin.promotion | Discounts and coupon codes |
sdk.admin.pricing | Price lists and rules |
sdk.admin.tax | Tax rates and providers |
sdk.admin.region | Regions, countries, and currencies |
sdk.admin.subscription | Recurring billing and plans |
sdk.admin.notification | Email and webhook configuration |
sdk.admin.analytics | Sales reports and metrics |
sdk.admin.store | Store settings and team management |
sdk.admin.upload | File and image uploads |
sdk.admin.collection | Product collections |
sdk.admin.customerGroup | Customer segmentation |
sdk.admin.salesChannel | Multi-channel sales |
sdk.admin.stockLocation | Warehouse and location management |
sdk.admin.apiKey | API key management |
CRUD Pattern
Every sub-module follows a consistent CRUD interface:
// List with pagination and filtering
const { data, count } = await sdk.admin.product.list({
limit: 20,
offset: 0,
sort: '-createdAt',
status: 'published',
})
// Get a single resource by ID
const product = await sdk.admin.product.get('prod_abc123')
// Create a new resource
const newProduct = await sdk.admin.product.create({
name: 'New Product',
price: 2999,
currency: 'USD',
})
// Update an existing resource
const updated = await sdk.admin.product.update('prod_abc123', {
name: 'Updated Name',
price: 3499,
})
// Delete a resource
await sdk.admin.product.delete('prod_abc123')Products
// Create a product with variants
const product = await sdk.admin.product.create({
name: 'Premium Hoodie',
slug: 'premium-hoodie',
description: 'Heavyweight cotton hoodie',
price: 5999,
currency: 'USD',
status: 'draft',
options: [
{ name: 'Size', values: ['S', 'M', 'L', 'XL'] },
{ name: 'Color', values: ['Black', 'Grey'] },
],
tags: ['apparel', 'winter'],
metadata: { brand: 'Hanzo' },
})
// Publish a product
await sdk.admin.product.update(product.id, { status: 'published' })
// List variants for a product
const variants = await sdk.admin.product.listVariants(product.id)
// Update a specific variant
await sdk.admin.product.updateVariant(product.id, 'var_001', {
sku: 'HOODIE-BLK-M',
price: 6499,
})Orders
// List orders with filters
const orders = await sdk.admin.order.list({
status: 'pending',
paymentStatus: 'authorized',
createdAfter: '2025-01-01T00:00:00Z',
sort: '-createdAt',
limit: 50,
})
// Get order details
const order = await sdk.admin.order.get('order_xyz789')
// Capture payment
await sdk.admin.payment.capture(order.payments[0].id)
// Create fulfillment
await sdk.admin.fulfillment.create({
orderId: order.id,
items: order.items.map(item => ({
itemId: item.id,
quantity: item.quantity,
})),
trackingNumber: '1Z999AA10123456784',
carrier: 'ups',
notifyCustomer: true,
})
// Issue a refund
await sdk.admin.payment.refund(order.payments[0].id, {
amount: 2999,
reason: 'Customer requested return',
})
// Cancel an order
await sdk.admin.order.cancel('order_xyz789', {
reason: 'Customer request',
})Customers
// List customers
const customers = await sdk.admin.customer.list({
q: 'jane',
limit: 20,
})
// Get customer with order history
const customer = await sdk.admin.customer.get('cust_abc123')
// Update customer
await sdk.admin.customer.update('cust_abc123', {
firstName: 'Jane',
metadata: { tier: 'gold' },
})
// Manage customer groups
await sdk.admin.customerGroup.addCustomers('group_vip', {
customerIds: ['cust_abc123'],
})Inventory
// Get inventory for a variant
const inventory = await sdk.admin.inventory.get('var_001')
// Update stock level
await sdk.admin.inventory.update('inv_001', {
quantity: 100,
lowStockThreshold: 10,
})
// Batch adjustment
await sdk.admin.inventory.batchUpdate([
{ variantId: 'var_001', adjustment: -5 },
{ variantId: 'var_002', adjustment: 20 },
])Promotions
// Create a percentage discount
await sdk.admin.promotion.create({
code: 'SUMMER20',
type: 'percentage',
value: 20,
startsAt: '2025-06-01T00:00:00Z',
endsAt: '2025-08-31T23:59:59Z',
usageLimit: 1000,
conditions: [
{ type: 'min_subtotal', value: 5000 },
],
})
// Create a fixed-amount discount
await sdk.admin.promotion.create({
code: 'SAVE10',
type: 'fixed',
value: 1000,
currency: 'USD',
usageLimit: 500,
})Analytics
// Revenue summary
const revenue = await sdk.admin.analytics.revenue({
period: '30d',
granularity: 'day',
})
// Top products
const topProducts = await sdk.admin.analytics.topProducts({
period: '30d',
limit: 10,
sortBy: 'revenue',
})
// Customer metrics
const metrics = await sdk.admin.analytics.customers({
period: '30d',
})Regions
// Create a region
await sdk.admin.region.create({
name: 'Asia Pacific',
currencyCode: 'JPY',
countries: ['JP', 'KR', 'SG', 'AU'],
taxInclusive: true,
paymentProviders: ['stripe'],
fulfillmentProviders: ['manual'],
})
// Update a region
await sdk.admin.region.update('reg_apac', {
countries: ['JP', 'KR', 'SG', 'AU', 'NZ'],
})Subscriptions
// Create a subscription plan
await sdk.admin.subscription.createPlan({
name: 'Monthly Box',
interval: 'month',
intervalCount: 1,
price: 3999,
currency: 'USD',
})
// List active subscriptions
const subscriptions = await sdk.admin.subscription.list({
status: 'active',
})
// Cancel a subscription
await sdk.admin.subscription.cancel('sub_001', {
cancelAtPeriodEnd: true,
})The admin module requires a secret API key. Never use it in client-side code. For storefront operations, use the Store module with a publishable key.
How is this guide?
Last updated on