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

# Create and update offers in bulk

> List a store’s master variants in a single createOffersWorkflow run, then update or delete them in bulk.

Pass a list of entries to `createOffersWorkflow` when you onboard a store’s catalog or run an import. One run creates every offer or none of them.

## Before you begin

You need these records in place:

* **A store and a member**: the `seller_id` and the `created_by` member id for every entry
* **Master variants**: one `variant_id` per row you import
* **A shipping profile and a stock location**: both owned by the store

> [!WARNING]
>
> Keep each run to one store. The workflow links all new inventory items to the store of the first entry, so mixing stores in one run assigns the other stores’ stock to the wrong store.

## Import a store’s rows

**1. Map your rows to offer entries**

Turn each source row into a `CreateOfferDTO` from `@mercurjs/types`.

```ts title="src/lib/to-offers.ts" theme={null}
import type { CreateOfferDTO } from "@mercurjs/types"

type Row = { variant_id: string; sku: string; price: number; qty: number }

export const toOffers = (rows: Row[]): CreateOfferDTO[] =>
  rows.map((row) => ({
    seller_id: "sel_01JD8Q1234567",
    created_by: "mem_01JD8Q1234567",
    shipping_profile_id: "sp_01JD8Q1234567",
    variant_id: row.variant_id,
    sku: row.sku,
    prices: [{ amount: row.price, currency_code: "eur" }],
    inventory_items: [
      {
        stock_levels: [
          { location_id: "sloc_01JD8Q1234567", stocked_quantity: row.qty },
        ],
      },
    ],
  }))
```

Each entry is independent and carries its own SKU, price, and starting stock.

**2. Run the workflow once for the batch**

Call the workflow with the mapped entries.

```ts title="src/api/admin/custom/offers/import/route.ts" theme={null}
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
import { createOffersWorkflow } from "@mercurjs/core/workflows"
import { toOffers } from "../../../../../lib/to-offers"

export async function POST(req: MedusaRequest, res: MedusaResponse) {
  const { rows } = req.body as { rows: Parameters<typeof toOffers>[0] }

  const { result } = await createOffersWorkflow(req.scope).run({
    input: { offers: toOffers(rows) },
  })

  res.status(201).json({ count: result.length })
}
```

The run emits one `offer.created` event per offer.

> [!NOTE]
>
> The batch is all or nothing. A missing variant, an entry without inventory items, or a SKU the store already uses fails the run, and compensation removes everything it created.

## Update offers in bulk

`updateOffersWorkflow` takes the same array shape, keyed by offer `id`. Every field except `id` is optional.

```ts theme={null}
import { updateOffersWorkflow } from "@mercurjs/core/workflows"

await updateOffersWorkflow(req.scope).run({
  input: {
    offers: [
      { id: "offer_01JD8Q1234567", sku: "ACME-LS-M-2" },
      {
        id: "offer_01JD8Q1234568",
        prices: [{ amount: 3900, currency_code: "eur" }],
      },
    ],
    updated_by: "mem_01JD8Q1234567",
  },
})
```

The first entry renames a SKU and keeps its prices. The second replaces that offer’s prices: send an existing price `id` to update a row in place, since rows left out are deleted. `updated_by` reaches the `offersUpdated` and `offerPricesUpserted` hooks.

## Delete offers in bulk

`deleteOffersWorkflow` takes a list of ids and soft-deletes the offer rows.

```ts theme={null}
import { deleteOffersWorkflow } from "@mercurjs/core/workflows"

await deleteOffersWorkflow(req.scope).run({
  input: { ids: ["offer_01JD8Q1234567", "offer_01JD8Q1234568"] },
})
```

The run emits `offer.deleted` per offer. Its `offersDeleted` hook gets a snapshot of each offer and its prices taken before the delete. The workflow has no step that removes the offer’s prices or inventory items.

## Next steps

* [Manage offer inventory](https://docs.mercurjs.com/platform/offer/guides/manage-offer-inventory.md)
* [How offer prices are replaced](https://docs.mercurjs.com/platform/offer/concepts/pricing-and-inventory.md)
* [Offer events](https://docs.mercurjs.com/platform/offer/reference/events.md)


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