Skip to content

CLI commands

The MockHub CLI, @mockhub/cli on npm, needs Node.js 22.19 or newer. Keep a project’s configuration in a repository shows how to start; mockhub <command> --help lists every option.

Exit code 2 always means an error: nothing was done, or the command says what was. Commands that compare also use 1, so a pipeline can fail on a difference.

Command Does Exits
init [--project P] [--env NAME] Writes mockhub.yaml for a project the token reaches, then pulls its configuration into it 0 written
validate [--remote] Checks the file against the document’s schema and its own references; --remote also asks the project 0 valid, 1 invalid
pull [--env NAME] Replaces the file’s configuration with the project’s, keeping the keys only the CLI reads 0 pulled
diff [--env NAME] Shows what push would change 0 no changes, 1 changes
push [--env NAME] [--yes] Applies the file, then loads its seed. Deletions need a confirmation on a terminal, or --yes, and are refused from a file that lists no mocks, scenarios, chaos profiles or webhooks 0 applied or nothing to change
store seed [--env NAME] Loads the file’s seed into the data store without applying the file 0 loaded
store reset [--env NAME] Empties the whole data store, then loads the file’s seed 0 loaded

When the file has no seed, store seed changes nothing, store reset only empties the store, and both say so and exit 0: Nothing to seed: mockhub.yaml names no collections under a top-level "seed" key, which maps each collection to its records by key.

Command Does Exits
store get COLLECTION [--key K] Prints one record with its etag, or a page of records searched with --query, filtered with --filter field:op:value (repeatable) and sorted with --sort -price,name 0 read
store put COLLECTION KEY --file FILE Writes one record from a JSON file; --create-only refuses a taken key 0 written
store delete COLLECTION [KEY] Deletes one record, several with --key K (repeatable), or every record --query and --filter match; a search only prints how many match until --yes, then deletes at that count 0 deleted, 1 matches without --yes
store export COLLECTION [--out FILE] Writes the collection as {"records": [...]}, to the file or the terminal 0 written
store import COLLECTION --file FILE Adds the file’s records, all or none; --overwrite replaces records whose key is taken, --replace makes the collection exactly the file 0 imported

A filter operator is eq, ne, gt, gte, lt, lte or like. A search delete is refused with Data store records changed when a mock wrote a matching record between the count and the delete. store put and store delete write whatever the record holds; a taken key is refused with Data store record exists. fixture capture and fixture apply take --collection NAME, repeatable, to save or put back those collections only, with no scenario; see Edit data store records.

Command Does Exits
env up NAME [--ttl HOURS] [--private] Creates the environment, or restarts its countdown, then applies the file and its seed 0 applied
env down NAME Deletes the environment and everything in it 0 deleted or already gone
env list Lists the workspace’s environments with their address and expiry 0 listed

See Create a preview environment for each pull request.

Command Does
pack list Lists the starter packs and the workspace’s own
pack apply ID [--fixture NAME] [--yes] Previews and installs a pack, replacing the project’s configuration and fixtures
pack save NAME [--description TEXT] Saves the project as a new version of a workspace pack; needs a personal token
pack delete ID [--yes] Deletes one saved version of a workspace pack; needs a personal token
fixture list Lists the project’s named fixtures
fixture capture NAME Saves the data store’s records and the scenarios’ states as a fixture
fixture apply NAME [--yes] Replaces every record and scenario state with the fixture’s
fixture export NAME --output FILE Writes a fixture to a file, with its records as captured
fixture save --file FILE Saves a fixture from a file

Each exits 0 when done. Off a terminal, pack apply, pack delete and fixture apply need --yes. See Start from a pack and Save and apply fixtures.

Command Does Exits
resource add NAME --path PATH Previews the mocks of a REST resource over the collection NAME and its findings, asks, then creates them inactive 0 created, 2 an error finding or a failed seed
Option Means
--from-example FILE A JSON record, or a list of them, to take the fields from and seed an empty collection with
--from-openapi COLLECTION ITEM The contract’s collection path and item path, such as /users /users/{id}
--from-collection Takes the fields from the records the collection holds; seeds nothing
--filters FIELDS, --sort FIELDS Comma-separated fields the list filters and sorts by
--shape envelope|array The list’s answer: {data, meta}, the default, or a bare list with X-Total-Count
--client-ids Keys records by the id the caller sends, answering 409 for one that exists
--activate Activates the created mocks
--yes Creates without asking; needed off a terminal

Pass at most one --from- option. The command adds mocks to the project, so a mockhub.yaml that holds its configuration is then behind: run pull. See Build a REST resource that remembers and Scaffold findings.

Command Does
idp init [--preset NAME] [--realm NAME] [--base-path PATH] [--redirect-uri URL] [--endpoint KEY] [--alg ALG] [--yes] Previews a preset’s endpoints and creates them as inactive mocks
idp status Lists the signing keys and the provider’s mocks
idp rotate [--yes] Rotates the signing keys; needs a personal token

--redirect-uri and --endpoint repeat. Off a terminal, idp init and idp rotate need --yes. See Mock an identity provider.

Command Does Exits
scenarios reset [--env NAME] [--project ID] Puts every scenario back in Started and every response sequence on its first step, those of inactive mocks included, as Reset all does 0 reset, 2 refused

It prints how many of each it reset, such as Reset 1 scenario(s) and 2 response sequence(s): the next request starts each from the beginning., and on a refusal the project’s reason. --project ID takes a project’s id instead of a target, such as an ephemeral environment’s; pass one or the other, not both. It needs the Editor role, and a machine token may run it, so a pipeline can start each test run from the same point. It changes no mock and no data store record; store reset empties the store. See Inspect and reset scenario state.

Command Does
access get Shows the access policy, its version, how many keys there are, and what it allows
access set [--mode M] [--policy P] [--allow A]… [--clear-allow-list] Changes only what the options name; asks first, or takes --yes
access-keys list Lists keys by name, prefix and id, never a value
access-keys create NAME --output FILE Creates a key and writes its value to a new file only you can read
access-keys revoke NAME Revokes a key at once; asks first, or takes --yes

Each exits 0 when done, and takes --project ID instead of --env to reach an ephemeral environment. See Make a project private.

Command Does Exits
openapi import Previews importing, updating or restoring a contract, then applies exactly that preview 0 applied or no change, 1 needs your decision
openapi import --dry-run Shows the preview only 0 no changes, 1 changes
openapi import --new-operations On an update, also imports the default response of each operation the active revision does not have 0 applied or no change, 1 needs your decision
openapi import --only-tag TAG Imports only the operations with this tag, or under a path with --only-path PATTERN, and what they refer to 0 applied or no change, 1 needs your decision
openapi bundle Writes a document whose references name other local files as one file, or part of a large one with --only-tag and --only-path, to upload on the OpenAPI tab 0 written
openapi diff --from N Compares two retained revisions, operation by operation 0 same, 1 different
openapi pull Downloads the active revision as uploaded, or a retained one with --revision 0 downloaded
openapi operations Lists the contract’s operations and the mocks linked to each 0 listed
openapi validate Checks responses from a HAR file, a JSON file or request logs against the contract, or with --direction request requests from a JSON file or request logs 0 none failed, 1 one failed
openapi probe Sends one valid request and single changes of it to find mocks that accept what the contract rejects 0 no counterexample, 1 one found

openapi validate takes --project ID instead of --env, such as an ephemeral environment’s. See Import a specification, Check request logs in bulk, Check the requests your application sent in CI, Check recorded responses in CI and Probe for permissive mocks.

Command Does Exits
mock default MOCK RESPONSE Makes one of a mock’s responses its default and prints the X-MockHub-Response value that asks for it on a single request 0 changed or already the default, 2 error or conflict

MOCK is the mock’s name or id and RESPONSE a response’s key. The command reads the mock and sends only the new selection with the version it read, so an edit made meanwhile is refused instead of overwritten. It changes no response, no other mock and not the mock’s activation, and the project’s address answers with the new default a moment later. --json prints the outcome (changed, unchanged or conflict) with the previous and the new default and the value to send. A mock that answers with a sequence has no default. See Choose the response that answers.

Command Does Exits
listen --forward-to URL [--path PREFIX] Relays every post to the project’s inbox to a local address, in order, until you stop it 0 stopped, 2 refused

--forward-to is an http or https address without a user name, password, query or fragment; the path after /__inbox is added to its path. --path stripe takes only posts under /__inbox/stripe, without that prefix. --timeout MS is how long each local answer may take, 30000 by default, and --skip-verify accepts any certificate from the --forward-to address, never from MockHub. --json prints one object a line as posts arrive. It needs a personal token, takes --project ID instead of --env, and stops with Ctrl-C. See Receive webhooks on your machine.

Command Does Exits
verify validate --file F Checks a suite against its schema, offline 0 valid, 2 invalid
verify run --file F Creates a run, runs every case against your application, seals the run and prints the report 0 passed, 1 an assertion failed, 2 anything else
verify start --file F Creates and starts a run for your own test framework, and prints each case’s dependency address and key, once 0 started
verify heartbeat RUN Renews an unexpired framework run’s lease; call every 20 seconds 0 renewed, 2 refused
verify open-case RUN CASE / verify seal-case RUN CASE Opens or seals a framework case’s observation interval 0 changed, 2 refused
verify finish RUN --results FILE Reports a framework’s JSON or JUnit results, seals the run and prints the report 0 passed, 1 an assertion failed, 2 anything else
verify report RUN / verify cancel RUN Prints a sealed run’s report, or cancels a run and deletes its projects as run for report, 0 for cancel

verify needs a machine token with Can create, list and delete ephemeral environments, and --workspace ID with a personal token. --json prints the report as the only document on stdout; progress goes to stderr. verify run --before-case COMMAND runs a command of yours before each case with MOCKHUB_CASE, MOCKHUB_DEPENDENCY_URL and MOCKHUB_DEPENDENCY_KEY set, so the application can be pointed at that case’s dependency, which expects the key in X-MockHub-Key. Ctrl-C cancels the run. Results the CLI or a framework reports are labelled client-reported in the report; only the dependency’s calls are observed by MockHub. See Verify an application against a mock dependency.

Option Means
-c, --config <path> The file to read. Without it, the CLI looks for mockhub.yaml here and in every parent directory
--token <token> The token, instead of MOCKHUB_TOKEN
--api-url <url> The API address, instead of apiUrl in the file
--env <name> The target to use. Needed when the file has more than one
--report-json <path> On diff, push and env up: writes the project’s full report to a file
Variable Means
MOCKHUB_TOKEN The token, when --token is not given
MOCKHUB_API_URL The API address. It wins over --api-url and apiUrl. Without any of them, https://api.mockhub.io
MOCKHUB_TIMEOUT_MS How long one request may take, in milliseconds. Without it, 30 seconds
NODE_EXTRA_CA_CERTS A certificate file to trust, for an API behind a company proxy that inspects HTTPS; see The CLI cannot reach MockHub

These keys sit in mockhub.yaml beside the configuration document. The CLI never sends them to the project, so diff ignores them and pull keeps them as written.

Key Holds
apiUrl The API address. HTTPS only, without a user name, password, query or fragment
environments.<name>.project The id of the project this target pushes to
environments.<name>.settings Settings merged over the top-level settings for this target
workspace The workspace’s id, where env up creates environments. Needed only with a personal token: a machine token carries its workspace
seed Records for the data store, by collection and key. push and env up replace each named collection with exactly these records, in order, after applying the file; other collections keep theirs
version: 3
openapi: null
apiUrl: https://api.mockhub.io
environments:
staging:
project: 0198f6a2-0000-7000-8000-000000000001
seed:
users:
u1: { id: u1, name: Ada }
u2: { id: u2, name: Grace }

A seed counts against the plan’s data store limits like any other record, and a seed that does not fit changes nothing. ${env:NAME} works in any string value, these keys included; see Values from the environment.

Report a problem with this page