> ## Documentation Index
> Fetch the complete documentation index at: https://docs.quickshops.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Merchant helpers (useMerchant)

> Server-only helpers for product CRUD, order lookup, ship, and refund, on the same /v1 API as MCP and qs.

> [!NOTE]
>
> **Server only.** Import from `@quickshops/sdk/merchant`. Never call `useMerchant()` from a `"use client"` file or the browser. Requires a trial or Pro API key (`HEADLESS_API_KEY`).

`useMerchant()` (alias of `createMerchantClient`) is the merchant-ops counterpart to [`useStore()`](https://docs.quickshops.app/sdk/installation). Use it when an agent or backend needs to mutate catalog or fulfill orders without opening the dashboard.

## Install

Requires **`@quickshops/sdk@1.3.0+`** (includes the `@quickshops/sdk/merchant` export):

```bash theme={null}
npm install @quickshops/sdk@^1.3.0
```

## Create a client

```ts lib/merchant.ts theme={null}
import "server-only";
import { useMerchant } from "@quickshops/sdk/merchant";

export const merchant = useMerchant();
```

Reads `HEADLESS_API_KEY` and optional `HEADLESS_API_URL` (default `https://api.quickshops.app`).

## Methods

| Method | HTTP | Notes |
| - | - | - |
| `listProducts({ includeInactive?, limit? })` | `GET /v1/products` | Catalog list |
| `createProduct(input)` | `POST /v1/products` | Requires `type`, `name`, `priceInCents`, `taxCode`; digital needs `downloadUrl` or `fileStorageKey` |
| `updateProduct(id, input)` | `PATCH /v1/products/:id` | Partial updates; rolls back Convex if Stripe sync fails |
| `deleteProduct(id)` | `DELETE /v1/products/:id` | Archives Stripe product then deletes; subscription products return conflict |
| `listOrders({ limit? })` | `GET /v1/orders` | Recent orders |
| `getOrder(id)` | `GET /v1/orders/:id` | Full order payload |
| `markOrderShipped(id, { trackingNumber?, carrier? })` | `POST /v1/orders/:id/ship` | Physical fulfill |
| `refundOrder(id, { lineItemIds?, restockInventory? })` | `POST /v1/orders/:id/refund` | Stripe refund via Connect |

## Example: create a digital product

```ts theme={null}
import { merchant } from "@/lib/merchant";

await merchant.createProduct({
  type: "digital",
  name: "Wallpaper pack",
  priceInCents: 900,
  taxCode: "txcd_10000000",
  description: "Desktop wallpapers",
  isActive: true,
  downloadUrl: "https://files.example.com/pack.zip",
});
```

## Example: ship and refund

```ts theme={null}
await merchant.markOrderShipped("ord_…", {
  trackingNumber: "1Z999…",
  carrier: "ups",
});

await merchant.refundOrder("ord_…", { restockInventory: true });
```

## Errors

Failed calls throw `QuickshopsMerchantError` with `statusCode`, `message`, and the API `code` (for example `VALIDATION_ERROR`).

```ts theme={null}
import { QuickshopsMerchantError } from "@quickshops/sdk/merchant";

try {
  await merchant.refundOrder("ord_…");
} catch (error) {
  if (error instanceof QuickshopsMerchantError && error.statusCode === 400) {
    console.log(error.message);
  }
}
```

## When to use what

| Goal | Use |
| - | - |
| Buyer-facing storefront | [`useStore()`](https://docs.quickshops.app/sdk/installation) + [`Storefront.*`](https://docs.quickshops.app/sdk/react) |
| Catalog / fulfill from your backend | `useMerchant()` |
| Desktop agent chat | [MCP](https://docs.quickshops.app/mcp/overview.md) |
| Shell / scripts | [`qs` CLI](https://docs.quickshops.app/cli/overview) |
| Reviewed store copy / theme | MCP `propose_store_changes` → `apply_store_changes` |

Interactive HTTP details live under [API → Catalog](https://docs.quickshops.app/api/products.md) and the Orders pages in the sidebar (generated from OpenAPI).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.