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

# Apply Variant Find Replace

> Apply a literal find-and-replace inside one text property.

Per-variant values (they differ per variant), constraint-validated
against one sibling fetch, **all-or-nothing**: a violation returns 400
with ``{message, failures, error}`` and nothing is written. Each
changed variant is stamped with the manual-edit override (R0.2) in the
same write, so the next feed import keeps the edit.

Send ``expected_will_change`` (the count the user confirmed from the
preview): if the count recomputed now differs, the write is refused
with ``error: "will_change_mismatch"`` (plus the recomputed
``will_change`` for callers without a preview to re-run).

**Authentication Required**: Requires ``variant:write`` permission.



## OpenAPI

````yaml /openapi/merchantops-public.json post /api/products/{product_key}/variants/bulk/find-replace
openapi: 3.1.0
info:
  description: >-
    Public API for the MerchantOps product catalog, pricing, and publishing
    surface.
  title: MerchantOps API
  version: 1.0.0
servers:
  - description: Production
    url: https://api.merchantops.ai
security: []
paths:
  /api/products/{product_key}/variants/bulk/find-replace:
    post:
      tags:
        - Variants
      summary: Apply Variant Find Replace
      description: |-
        Apply a literal find-and-replace inside one text property.

        Per-variant values (they differ per variant), constraint-validated
        against one sibling fetch, **all-or-nothing**: a violation returns 400
        with ``{message, failures, error}`` and nothing is written. Each
        changed variant is stamped with the manual-edit override (R0.2) in the
        same write, so the next feed import keeps the edit.

        Send ``expected_will_change`` (the count the user confirmed from the
        preview): if the count recomputed now differs, the write is refused
        with ``error: "will_change_mismatch"`` (plus the recomputed
        ``will_change`` for callers without a preview to re-run).

        **Authentication Required**: Requires ``variant:write`` permission.
      operationId: apply_variant_find_replace
      parameters:
        - in: path
          name: product_key
          required: true
          schema:
            title: Product Key
            type: string
        - in: header
          name: authorization
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: Authorization
        - in: header
          name: X-Organization-ID
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: X-Organization-Id
        - in: cookie
          name: stytch_session
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: Stytch Session
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/VariantFindReplaceRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/VariantFindReplaceApplyResponse'
          description: Successful Response
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
          description: Validation Error
components:
  schemas:
    VariantFindReplaceRequest:
      description: Body for BOTH the preview (dry run) and the apply route.
      properties:
        case_sensitive:
          default: false
          description: 'Default: case-insensitive matching.'
          title: Case Sensitive
          type: boolean
        expected_will_change:
          anyOf:
            - minimum: 0
              type: integer
            - type: 'null'
          description: >-
            Apply only: the will_change count the user confirmed from the
            preview. When set and it differs from the count recomputed at apply
            time, the write is refused with error 'will_change_mismatch' and the
            recomputed count. Ignored by preview.
          title: Expected Will Change
        find:
          description: Literal text to find (never a regex).
          minLength: 1
          title: Find
          type: string
        property_key:
          description: Variant-level property to edit.
          minLength: 1
          title: Property Key
          type: string
        replace:
          default: ''
          description: Literal replacement; may be empty (deletes the match).
          title: Replace
          type: string
        variant_keys:
          items:
            type: string
          maxItems: 5000
          minItems: 1
          title: Variant Keys
          type: array
      required:
        - variant_keys
        - property_key
        - find
      title: VariantFindReplaceRequest
      type: object
    VariantFindReplaceApplyResponse:
      properties:
        matched:
          title: Matched
          type: integer
        modified:
          title: Modified
          type: integer
      required:
        - matched
        - modified
      title: VariantFindReplaceApplyResponse
      type: object
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          title: Detail
          type: array
      title: HTTPValidationError
      type: object
    ValidationError:
      properties:
        ctx:
          title: Context
          type: object
        input:
          title: Input
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          title: Location
          type: array
        msg:
          title: Message
          type: string
        type:
          title: Error Type
          type: string
      required:
        - loc
        - msg
        - type
      title: ValidationError
      type: object

````