Skip to content

Admin API guide

Call the EdgeCart Admin API with the typed client or a raw request.

The Admin API powers the EdgeCart back office. Use it to automate catalog, orders, fulfillment, payments, customers, promotions, and store setup.

Credentials

Every request needs:

  • a signed-in store member’s Better Auth session cookie, and
  • the x-store-id header.

The browser admin sends both automatically. A server-side integration must forward the cookie; do not use a secret key as an admin session.

Typed client

import { createAdminApi } from "@edgecart/admin-api";

const api = createAdminApi({ storeId: "store_123" });

const { products, count } = await api.products.list({ limit: 20, q: "cap" });
const product = await api.products.create({ title: "Cap" });
await api.products.update(product.id, { status: "published" });

const { orders } = await api.orders.list({ status: "pending", limit: 20 });
const order = await api.orders.get(orders[0].id);

const fulfillment = await api.orders.fulfillments.create(order.id, {
  items: [{ id: order.items[0].id, quantity: 1 }],
});
await api.fulfillments.ship(fulfillment.id, {
  tracking_numbers: ["TRACK"],
});

Resource methods unwrap list envelopes, so the result is the DTO collection ({ products, count }) rather than the raw response.

Raw requests

createAdminRequest is the escape hatch for routes that do not have a resource helper yet:

import { createAdminRequest } from "@edgecart/admin-api";

const admin = createAdminRequest({
  storeId: "store_123",
  apiBaseUrl: "https://shop.example/api",
});

const { products } = await admin<{ products: Product[] }>("/products");
await admin("/products", {
  method: "POST",
  body: { title: "Cap" },
  idempotencyKey: crypto.randomUUID(),
});

Uploads

import { uploadAdminImage } from "@edgecart/admin-api";

await uploadAdminImage({ storeId: "store_123" }, file);

The helper posts the file to the uploads route and returns the stored image.

Errors

Non-2xx responses become AdminApiError with status, type, and code. Cross-store access returns 404; validation errors return 400 with a type/code pair. See API conventions.

Pagination and fields

List endpoints accept offset and limit and return { <plural>, count, offset, limit }. Some endpoints accept fields= to select a subset of fields.

Type to search…

↑↓ navigate↵ selectEsc close