Quick answer: Mockoon's admin API is a runtime control plane mounted at /mockoon-admin on the same port as the mock itself. A remote script can change variables, regenerate data buckets, read transaction logs, and reset state without a restart, but every change lives in the running process and is lost when the server stops. It is not a way to edit your saved mock configuration.
What the admin API controls
Every running mock serves the admin API next to its normal routes. The API prefix does not apply to this path, so a mock on http://localhost:3000 answers at http://localhost:3000/mockoon-admin regardless of any route prefix.
| Endpoint | Methods | Effect on the running mock |
|---|---|---|
/mockoon-admin/state | GET, PURGE | A purge resets request counters, regenerates buckets, clears global variables, and clears logs |
/mockoon-admin/global-vars | POST, PUT, PATCH, PURGE | Sets or clears values shared across routes until the process stops |
/mockoon-admin/env-vars | POST, PUT, PATCH | Updates runtime environment values without touching the operating system |
/mockoon-admin/logs | GET, PURGE | Reads recorded transactions or clears the log |
/mockoon-admin/data-buckets | GET, POST | Regenerates buckets without a full state reset |
The two variable endpoints are easy to confuse. Environment variables carry the MOCKOON_ prefix by default, or the one set with --env-vars-prefix; a key without it gets the prefix added. The update changes only what the process reads through getEnvVar, never the host shell or the data file. Global variables are the store behind setGlobalVar and getGlobalVar, shared across routes of one environment, reset on restart, and never shared between environments.
Where remote control earns its place
The admin API fits headless and CI runs where restarting a container is slower than calling the mock. A typical run starts the CLI, posts a variable to select a branch-specific response, drives the client, then fetches the logs and asserts on the requests the mock received. A final purge gives the next case a clean counter, fresh buckets, and empty logs without reloading the file.
Treat this as test orchestration, not a configuration database. Nothing is persisted, so the script must set every value it needs at the start of each run; behavior that survives a restart belongs in the mock file. The comparison hub covers the wider trade-offs between file-defined mocks and runtime control.
The security boundary
The control plane and data plane share one port and cannot use separate listeners, so anyone who reaches the mock port can attempt the admin path. Current releases require Authorization: Bearer <token> on every request and return 401 when it is missing or wrong. In the CLI, pin a token with --admin-api-token; otherwise Mockoon generates a random one at startup, prints it once, and changes it on every restart. The desktop app shows its per-launch token in Settings.
By default the admin API sends no CORS headers, so a page on another origin cannot call it from a browser. The CLI can add one origin with --admin-api-cors-origin; desktop mocks cannot be opened to cross-origin calls. A local-first tool such as Powerduck keeps the mock in the desktop main process and verifies behavior through ordered scenario assertions rather than exposing a remote admin surface, which removes that control plane entirely.
For a CLI or serverless mock listening beyond localhost, disable it with --disable-admin-api or set enableAdminApi: false. The desktop app cannot disable it, so do not bind a desktop mock to an interface others can reach. Anyone with the token can purge the full state, so keep it out of images, source files, and logs.
Frequently asked questions
Does the admin API edit my mock file? No. It changes in-memory runtime state only. The data file stays untouched, and a restart returns the mock to the behavior defined in that file.
Is the admin API on a separate port? No. It is served under /mockoon-admin on the same port as the mock, so network access to the mock is also access to the admin path, gated by the bearer token.
What if I do not pass a token in the CLI? Mockoon generates a random token at startup and prints it once. It changes on every restart, so pin one with --admin-api-token for repeatable scripts.
The bottom line
Use the admin API as a short-lived control plane for test runs: drive runtime variables and reset state from a script, keep durable behavior in the mock file, and never assume a change survives a restart. For any CLI mock that listens past localhost, pin a strong token or disable the admin API outright, because the same port that serves your mock also serves the control plane.


