Getting started
@eldrajs/sdk is a small client for your shop's public API. It reads products, content and carts, and hands the cart to Eldra's checkout. It works in any framework, in the browser and on a server.
Want something on screen first? Do the Quickstart. This page covers what you need for a real project. Every detail is in the SDK reference.
Install and connect
pnpm add @eldrajs/sdkimport { createEldraClient } from '@eldrajs/sdk';
export const eldra = createEldraClient({ orgId: 'your-organisation-id' });Your organisation id is in Studio under Settings → API & tracking, as Organization ID. There is no API key, because everything a storefront reads is public.
Create the client once and share it. It keeps no state, so one per server request is fine too.
Register your site's address
Anyone may read your shop's products and content, from any address. Changing a cart, applying a discount, ordering and submitting a form only work from addresses you registered. In Studio, go to Settings → General → Site addresses: your storefront address counts, and Other sites takes previews and http://localhost:5173 (or your dev port).
From any other address those calls fail with ORIGIN_NOT_REGISTERED, and analytics ignores the visits. Calls from a server are not affected.
Typed responses
Add the Vite plugin, and every call is typed against your own shop: its products, its content types, its API version.
// vite.config.ts
import { eldra } from '@eldrajs/sdk/vite';
export default defineConfig({
plugins: [eldra({ orgId: process.env.ELDRA_ORG_ID })],
});The plugin writes a .eldra/web-studio/ folder when you start the dev server or build. Commit that folder. Your CI then type-checks without reaching Eldra, and API changes show up in pull requests.
Nuxt
Add the folder to Nuxt's type check too, or every response stays unknown:
// nuxt.config.ts
export default defineNuxtConfig({
vite: { plugins: [eldra({ orgId: process.env.ELDRA_ORG_ID })] },
typescript: { tsConfig: { include: ['../.eldra/**/*.ts'] } },
});Without the plugin, name the fields you read at the call site:
const products = await eldra.catalog.listProducts<{ data: { title: string }[] | null }>();What you can do
| Area | For example |
|---|---|
catalog | List and search products, read a product, categories, collections and brands |
cms | Read your content types: pages, blog posts, anything you built in Studio |
cart | Add, change and remove items, apply discount codes and gift cards |
checkout | Get the address of Eldra's hosted checkout for a cart |
orders | Show an order after checkout |
forms | Show and submit forms built in Studio |
The SDK reference lists every method.
Let the server do the sums
Use the cart's totals as they come. Never add up lines in your storefront: discounts, tax and shipping are worked out by Eldra.
Keep the cart between visits
import { createCartSession } from '@eldrajs/sdk';
const cartSession = createCartSession();
const cart = await eldra.cart.addItem({
cartId: cartSession.read() ?? undefined,
productId,
variantId,
quantity: 1,
});
cartSession.remember(cart.id);createCartSession stores the cart id in the browser. If a request fails with CART_NOT_FOUND, call cartSession.forget() and start a new cart.
Send the shopper to checkout
const checkoutUrl = await eldra.checkout.url({ cartId, locale: 'is-IS' });
window.location.href = checkoutUrl;Checkout is hosted by Eldra. Payment, delivery and the receipt happen there, so your site has none of that to build.
Handle errors
Every failed call throws an EldraHttpError. Check its errorId, never the message:
import { EldraHttpError } from '@eldrajs/sdk';
try {
await eldra.cart.applyCode(cartId, code);
} catch (error) {
if (error instanceof EldraHttpError && error.errorId === 'CART_DISCOUNT_EXHAUSTED') {
showMessage('That code has been used up.');
}
}Staging and local development
The client talks to production by default. Point it somewhere else with apiBaseUrl:
createEldraClient({ orgId, apiBaseUrl: 'https://web.staging.eu.eldra.app/api' });Checkout follows along: a staging cart goes to the staging checkout.
More than one website
If your organisation runs several websites, say which one you read with siteId. You find it in Studio under the site's settings.
createEldraClient({ orgId, siteId: 'your-site-id' });Next
- Components: ready-made, accessible Vue components for your storefront.
- Images: product photos at the right size on every screen.
- Rich text: render content written in Studio's editor.
- SDK reference: preview mode, forms, analytics, campaign tracking and the links Eldra's emails point to.