API and code · Mock server docs

The project mock config

The mock server is part of every plan except Time only. Request access · See the plans

One config per project, with a rev. It holds what is not tied to one endpoint: the mock login, the 401 answer, scenarios and confirm codes. Every key is optional.

{
  "login": {
    "usernameField": "username",
    "passwordField": "password",
    "tokenField": "token",
    "users": [{ "username": "sam.tester@example.com", "password": "Test-pass-1", "state": { "customerName": "Sam Tester" } }],
    "failStatus": 400,
    "failBody": { "non_field_errors": ["Unable to log in with provided credentials."] }
  },
  "unauthorized": { "status": 401, "body": { "detail": "Invalid token." } },
  "scenarios": [
    { "name": "New customer", "state": { "accountActive": true, "balance": 0, "orders": [] } }
  ],
  "confirmCodes": ["123456"]
}

Read and save it with MCP get_mock_config / save_mock_config (Editing with MCP) or the API GET|PUT /orgs/<org>/projects/<project>/mock-config ({rev, config}). Every member reads it; owners and admins save it. A save replaces the whole config; a stale rev answers 409 with the current config. rev 0 = none saved yet.

login

KeyWhat
usernameField, passwordFieldThe request fields of the login endpoint (JSON or form body; dotted names reach nested JSON).
tokenFieldThe answer's token field when the login endpoint has no preset (default "token").
users1..50 test users {username, password, state?}. state is merged on top of the session's state at login.
failStatus, failBodyThe answer to wrong credentials (default 400 {"error":"invalid_credentials"}).

The login endpoint is the one with "mock": {"login": true}. A right username + password gets a new token (mt_…):

  • the answer is the endpoint's preset (it can name the token with "{{auth.token}}"), else {"<tokenField>": "mt_…"};
  • in a session (session URL or header) the token belongs to that session;
  • without a session the login makes a new session (its scenario: the X-Mock-Scenario header); later calls with the token run in it.

With a login set up, it is strict: every endpoint with auth required accepts only a token the mock issued and not yet logged out. On a session URL the token must be one of that session's. Anything else gets the unauthorized answer. Without a login in the config, any Authorization header passes, as before.

The password never reaches the request log ("***").

unauthorized

{status?, body?}: the answer to a call without a valid issued token (default 401 {"error":"Invalid token"}). Status 400..599.

scenarios

{
  "scenarios": [
    {
      "name": "Account not active",
      "state": { "accountActive": false, "cashActive": true },
      "presets": [
        { "endpointId": "account-status", "status": 200, "body": { "accountActive": false, "notice": "Your account is being reviewed." } }
      ]
    }
  ]
}
KeyWhat
name1..80 characters, one line, unique in any case. Sessions name it (any case).
stateThe start state: an object, top-level keys letters / digits / _ - (no dots), ≤ 64 KB.
presets≤ 200 answers {endpointId, status, when?, match?, final?, body}, like an endpoint's presets. In a session on this scenario they come before the endpoint's own presets.

Each preset must name an endpoint of the project and one of its documented statuses; match keys must be documented fields of that endpoint.

confirmCodes

The codes a confirm endpoint with a codeField accepts: 1..20 codes of 1..20 characters, no duplicates. Default ["123456"].

Limits

The whole config ≤ 512 KB; 100 scenarios; 50 users; usernames and passwords ≤ 200 characters.