> ## 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.

# createProductChangeWorkflow

> Create ProductChange records after validating no pending change exists per product.

Creates one or more `ProductChange` records — the staging entity for vendor edits on shared master products. Validates that none of the referenced products already has a `pending` change before inserting. Emits `product-change.created` with one `{ id }` entry per change. Actions are attached separately (see `stageProductChangeWorkflow` for the combined flow).

## Usage

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

const { result } = await createProductChangeWorkflow(container).run({
  input: {
    changes: [
      { product_id: "prod_01H...", created_by: "sel_01H..." },
    ],
  },
})
```

## Input

<ParamField body="changes" type="CreateProductChangeDTO[]" required>
  Changes to create.

  <Expandable title="properties">
    <ParamField body="product_id" type="string" required>
      Id of the product the change targets. Must not already have a pending change.
    </ParamField>

    <ParamField body="status" type="ProductChangeStatus">
      One of `pending`, `confirmed`, `declined`, `canceled`; audit-trail rows are created already `confirmed`.
    </ParamField>

    <ParamField body="created_by" type="string">
      Actor id who authored the change.
    </ParamField>

    <ParamField body="internal_note" type="string">
      Operator-only note.
    </ParamField>

    <ParamField body="external_note" type="string">
      Vendor-facing note.
    </ParamField>

    <ParamField body="confirmed_by" type="string">
      Confirming actor id, for pre-confirmed rows.
    </ParamField>

    <ParamField body="confirmed_at" type="Date">
      Confirmation timestamp, for pre-confirmed rows.
    </ParamField>

    <ParamField body="metadata" type="object">
      Arbitrary key-value data stored on the change.
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="additional_data" type="object">
  Arbitrary data forwarded to the `productChangeCreated` hook.
</ParamField>

## Result

<ResponseField name="result" type="ProductChangeDTO[]">
  The created change records with ids, statuses, and timestamps.
</ResponseField>

## Hooks

<ResponseField name="validate" type="hook">
  Runs first with `{ input }` — use it to reject invalid payloads before creation.
</ResponseField>

<ResponseField name="productChangeCreated" type="hook">
  Runs after creation with `{ changes, additional_data }`.
</ResponseField>
