Getting Started
Quickstart
Fetch products, handle errors, and bootstrap cart/invoice state.
Basic read flow
import { createSazitoClient } from '@sazito/client-sdk';
const client = createSazitoClient({
domain: 'mystore.sazito.com',
});
const productsRes = await client.products.list({
page: 1,
pageSize: 12,
sort: 'newest',
});
if (productsRes.error) {
console.error(productsRes.error.message);
} else {
console.log(productsRes.data.items);
}Single product by URL path or slug
const byPath = await client.products.get('/product/running-shoe-pro');
const bySlug = await client.products.get('running-shoe-pro');Minimal cart and invoice bootstrap
const cartRes = await client.cart.addItemWithAttributes(12345, 1);
if (cartRes.error) {
throw new Error(cartRes.error.message);
}
const invoiceRes = await client.invoices.create();
if (invoiceRes.error) {
throw new Error(invoiceRes.error.message);
}
console.log(invoiceRes.data.totalPrice);Add the checkout component
For a complete React/Next.js checkout UI, install the companion package and import its stylesheet once:
pnpm add @sazito/client-sdk @sazito/checkout react@18 react-dom@18'use client';
import '@sazito/checkout/styles.css';
import { SazitoCheckoutPage, SazitoProvider } from '@sazito/checkout/next';
export function CheckoutPage() {
return (
<SazitoProvider client={client}>
<SazitoCheckoutPage
credentials={{ cart: { identifier: '<cart-identifier>' } }}
config={{
locale: 'fa',
continueShoppingUrl: '/',
}}
/>
</SazitoProvider>
);
}The component provides the cart → shipping → payment → result flow and
reuses credentials stored by the same SDK client. See the full
checkout guide for payment returns, theming,
analytics, custom buttons, and custom layouts.
Authenticated profile call
client.setAuthToken('<jwt>');
const me = await client.users.getCurrentUser();Every SDK method returns a unified response object. Always branch on
response.error before reading response.data.