---
title: "Replace a mock's rules"
method: PUT
path: "/v1/runs/{runId}/resources/{resourceId}/mock"
tags: ["Resources"]
---

# Replace a mock's rules

`PUT /v1/runs/{runId}/resources/{resourceId}/mock`

## Request

- Base URL: `https://api.ironfang.com/rig`
- URL: `https://api.ironfang.com/rig/v1/runs/{runId}/resources/{resourceId}/mock`
- Auth: one of:
  - HTTP bearer
  - HTTP bearer

Replaces the rules a mock_http resource answers with, in order, while the run is active. The first rule whose match holds decides the response; no match answers 404 with code `no_mock_rule`. The change is recorded on the timeline as `mock.rules.updated`. Needs rig.run.

## Request body

- object
  - `rules` MockRule[], required
    - `match` object, required
      - `headers` object: Headers that must be present with exactly these values.
      - `json` object: Top-level fields a JSON request body must equal.
      - `method` string: An HTTP method, or "*" or omitted for any.
      - `path` string: Exact path under the mock URL, a prefix ending in "/*", or a template whose {name} segments match any one segment; omitted for any.
    - `repeat` 'last' | 'cycle': After a sequence's last response: keep giving the last (the default) or start again.
    - `respond` MockResponse: One answer. With template, the body and the header values are rendered from the request: {{request.method}}, {{request.path}}, {{request.query}}, {{request.query.name}}, {{request.header.Name}}, {{request.body}}, {{request.json.a.b.0}}, {{run.id}}, {{resource.name}}, {{step}}, {{call}} and {{received_at}}. In a json body a placeholder sits inside a string and is escaped for it. An unknown placeholder is refused when the rules are written.
      - `body` string: A text body; exclusive with json.
      - `delay` string: Held before answering, a duration such as "250ms", at most 10s.
      - `headers` object
      - `json` unknown
      - `status` integer, required
      - `template` boolean: Render the body and header values from the request.
    - `sequence` MockResponse[]: The responses this rule gives its calls in turn; exclusive with respond. Replacing the rules starts every sequence afresh.
      - `body` string: A text body; exclusive with json.
      - `delay` string: Held before answering, a duration such as "250ms", at most 10s.
      - `headers` object
      - `json` unknown
      - `status` integer, required
      - `template` boolean: Render the body and header values from the request.

## Response `200`

The resource with its new rules

- object
  - `resource` Resource, required
    - `config` object
    - `created_at` string, date-time, required
    - `email_address` string: For email resources - the inbox that receives for this run.
    - `expires_at` string, date-time, required
    - `id` string, uuid, required
    - `name` string, required
    - `organisation_id` string, uuid, required
    - `public_url` string, uri: For callback and mock resources - the unguessable URL to configure elsewhere.
    - `route_label` string: For connector routes, and callbacks forwarded through one.
    - `run_id` string, uuid, required
    - `scope` 'run', required
    - `type` 'email' | 'callback' | 'mock_http' | 'connector_route', required

## Other responses

- `400`: The body is not one strict JSON value of the documented shape (`invalid_json`).
- `401`: No credential, an invalid one, or a delegated token where none is accepted (`unauthorized`, `invalid_api_key`, `delegated_not_allowed`).
- `403`: The credential lacks the permission or scope, or names another organisation (`forbidden`, `insufficient_scope`).
- `404`: No such object in this organisation (`not_found`).
- `409`: The run has already ended (`run_not_active`).
- `422`: A field is invalid; the message names it (`invalid_request`).

---

[API](https://skmtc.dev/ironfang/apis/ironfang-rig-api.md) · [All operations](https://skmtc.dev/ironfang/apis/ironfang-rig-api/llms.txt) · [OpenAPI document](https://skmtc.dev/ironfang/apis/ironfang-rig-api/revisions/3e86a312dad1?raw)
