The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.
TypeScript b2b-marketplacecomposable-commerceecommerceenterpriseheadless-commercemarketplacemedusamedusajsmulti-vendortypescript
---
title: "Create and update offers in bulk"
sidebarTitle: "Bulk-create offers"
description: "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.
</Warning>
## Import a store’s rows
<Steps>
<Step title="Map your rows to offer entries">
Turn each source row into a `CreateOfferDTO` from `@mercurjs/types`.
```ts title="src/lib/to-offers.ts"
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.
</Step>
<Step title="Run the workflow once for the batch">
Call the workflow with the mapped entries.
```ts title="src/api/admin/custom/offers/import/route.ts"
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.
</Step>
</Steps>
<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.
</Note>
## Update offers in bulk
`updateOffersWorkflow` takes the same array shape, keyed by offer `id`. Every field except `id` is optional.
```ts
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
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](/platform/offer/guides/manage-offer-inventory)
- [How offer prices are replaced](/platform/offer/concepts/pricing-and-inventory)
- [Offer events](/platform/offer/reference/events)