Bỏ qua để đến nội dung
REST API quickstart Drive MZPanel over HTTP with a Bearer API token — discovery, curl examples for servers, sites and jobs, strict request bodies, the error envelope and per-plan rate limits.

REST API quickstart

Nội dung này hiện chưa có sẵn bằng ngôn ngữ của bạn.

The REST API is the same management surface as MCP, reachable with plain HTTP. Use it from scripts, CI, or LLM tools that can only make HTTP calls (a ChatGPT action, a function-calling loop). It is on every plan. On Free, writes are a 30-day trial, then read-only (402 automation_trial_ended); Plus and up have full automation.

  • Base URL: https://api.mzpanel.com
  • Auth: Authorization: Bearer mzmcp_… (mint the token at Advanced → Developer, /developer; see Tokens, levels & scopes)
  • Bodies: JSON, Content-Type: application/json
  1. The full management API: the dashboard’s own /v1/* routes, called with your Bearer token. A bridge checks the token’s level, opt-in scope, server allowlist and plan, then runs the exact handler the dashboard uses. The list of callable operations is GET /v1/api/operations. Any route not in that list answers 403 not_exposed.
  2. Convenience endpoints under /v1/api/*: a few synchronous shortcuts that return the result inline: whoami, servers, servers/{id} (+ /sites, /services, /php, /databases, /updates, /cron, /docker from the cache), /metrics, /logs?source=, /ssl, POST /services/{name}/{action}, POST /ssl/renew, POST /sites/{domain}/cache/purge and POST /updates/apply.

Both doors are described in one OpenAPI 3.1 document, GET /v1/openapi.json (whole API, or ?tag=dns for one area). To load it into Postman, n8n, Make or Pipedream, see Import the API.

Prefer door 1 for anything beyond a quick read: it covers everything (about 350 operations, including every on-box job kind).

Terminal window
export MZ=https://api.mzpanel.com
export TOKEN=mzmcp_YOUR_TOKEN
# Token identity: access_level, org_id, server_scope ("all" or ids), role
curl -s $MZ/v1/api/whoami -H "Authorization: Bearer $TOKEN"
# Every operation + job kind + danger scope, annotated for this token
curl -s $MZ/v1/api/operations -H "Authorization: Bearer $TOKEN" > operations.json
# The JSON Schema of one job kind's body
curl -s $MZ/v1/api/job-kinds/site.create -H "Authorization: Bearer $TOKEN"

In operations.json, each entry of operations[] has id, mcp_tool, method, path, summary, level, scope, min_tier, body and allowed_for_this_token. Each entry of job_kinds[] has type, level, scope, min_tier, rbac_group and fields. Paths are written as /v1/servers/{id}/… or /v1/servers/:id/…; both mean a path parameter.

Terminal window
curl -s $MZ/v1/servers -H "Authorization: Bearer $TOKEN" # servers
curl -s $MZ/v1/servers/sites/all -H "Authorization: Bearer $TOKEN" # every site, every type
curl -s $MZ/v1/servers/stacks/all -H "Authorization: Bearer $TOKEN" # compose stacks
curl -s $MZ/v1/servers/docker/all -H "Authorization: Bearer $TOKEN" # Docker apps
SID=<server uuid>
curl -s $MZ/v1/servers/$SID/inventory/services -H "Authorization: Bearer $TOKEN"

/v1/servers/{id}/inventory/{kind} returns {items, meta, synced_at, is_online} from the agent-pushed cache. The kinds are sites php php_detail ssl databases db_users db_engine pg_engine mongo_engine cron users ssh_keys stacks docker images volumes networks mail services daemons security extensions wp_content site_usage plans dns storage updates facts routes. POST …/inventory/{kind}/refresh asks the agent to re-collect a kind; read it again a few seconds later and compare synced_at.

Terminal window
# Create a static site (siteType decides the stack; WordPress is just one value)
curl -s -X POST $MZ/v1/servers/$SID/jobs \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{"type":"site.create","domain":"docs.example.com","siteType":"static"}'
# → 202 {"job_id":"…","status":"running","stream_url":"/v1/jobs/…/stream"}
JOB=<job_id>
curl -s $MZ/v1/jobs/$JOB -H "Authorization: Bearer $TOKEN"
# → {"job":{"id","type","status","exitCode","errorMessage","dispatchedAt","completedAt","durationMs"}}
# Live output (server-sent events: `log` frames, then one `done` frame)
curl -N -s $MZ/v1/jobs/$JOB/stream -H "Authorization: Bearer $TOKEN"

Job-kind fields sit at the top level next to "type". Statuses, the offline queue and retry rules are covered in Jobs.

Bearer requests are validated strictly. The dashboard silently drops unknown keys, but an API client gets them rejected, so a misspelt field is never a silent no-op:

{
"error": {
"code": "bad_request",
"message": "Unrecognized key \"site_type\" (did you mean \"siteType\"?) for job type \"site.create\". GET /v1/api/job-kinds/site.create shows its schema.",
"details": { "unrecognized_keys": ["site_type"], "accepted_keys": ["type", "domain", "siteType", "…"] }
}
}

Non-job routes report unknown keys in the X-Mz-Unrecognized-Keys response header and fail with 400. Fix the key; don’t just drop it. Keys are exactly as documented in each operation’s body (mostly camelCase; a few older routes use snake_case, such as destination_ids on backup jobs).

Every error uses one envelope. Switch on error.code, never on message:

{ "error": { "code": "scope_required", "message": "…", "details": { "required_scope": "sites:delete" } } }

The /v1/api/* shortcuts may add error.status. Ignore any field you don’t recognize.

HTTPcodeMeaningWhat the agent should do
401unauthorizedToken missing, invalid, expired or revoked, or its owner was deletedStop. Ask the user for a valid token.
403not_exposedThe route or job kind is never available to tokens (billing, 2FA, terminal, docker.exec, …)Don’t look for a workaround. Tell the user to do it in the dashboard.
403access_levelThe token’s level is too low (details.required_level)Ask the user for an operate or full token.
403scope_requiredThe operation needs an opt-in scope (details.required_scope)Ask the user to mint a token that carries that scope. Scopes can’t be added later.
403fleet_wideThe operation touches servers beyond the request, and the token has a server allowlistUse a token without an allowlist.
403token_ip_deniedThe token has an Allowed IPs list and this request came from another address (the message names it)Don’t retry from there. Tell the user to add that public IP on the Developer page, or run from an allowed machine.
403tier_requiredThe workspace plan is too low (details.required_tier on the bridge)Report the plan needed. Don’t retry.
403forbidden / site_permissionThe token owner’s team role, or the site owner’s share settings, don’t allow itReport it. The org owner changes roles at /team.
404not_foundWrong id, or outside the token’s server/mailbox allowlist (deliberately 404, not 403)Re-list ids with servers_list. Check server_scope in whoami.
400bad_requestInvalid body: unknown keys, wrong types, failed validation (details lists them)Fix the body using the schema.
402server_limitAdding a server would exceed the plan’s VPS quota (details.limit, details.used)Report it. The user upgrades or buys a vps-slot add-on.
402app_limitCreating a new Docker app or stack would exceed the plan’s Docker apps & stacks quota (details.used, details.limit, details.tier)Report it. The user deletes an app or stack, or upgrades. Redeploying an existing name is never blocked.
402automation_trial_endedA write on the Free plan after its 30-day automation trial (details.required_tier: "plus", details.trial_ended_at); reads still workDon’t retry. Tell the user to upgrade to Plus or make the change in the dashboard.
400bad_upload / domain_requiredapps_deploy: the uploadId is unknown, used or not uploaded yet; or a new app has no domain and no instant URLUpload again with apps_source_upload + its curl; or pass domain.
409agent_update_requiredThe server’s agent is too old for this call (details.current, details.required)Run agent_update on the server, then retry.
503direct_upload_unavailableDirect uploads to this server aren’t availableDeploy from Git (source: {git: {url}}) instead.
409server_offlineThe agent is disconnected, and this kind is never queued (it carries secrets or env values)Wait for the server to come online. Check servers_list, then retry once.
429rate_limitedOver the per-token budgetSleep for the Retry-After seconds, then continue.
502git_token_failed and other *_failed codesA third-party call (Git provider, DNS provider, ACME) failedRead message, fix the upstream cause, then retry.

Limits are per token per minute and set by the workspace plan: Free 60, Plus 120, Pro 300, Max 600. MCP and REST share one budget. A 429 carries Retry-After (seconds). Poll jobs every 2–5 seconds rather than in a tight loop.

Billing, payments and wallet; account identity, emails, sessions and 2FA; the staff console; interactive terminal sessions; install-over-SSH and agentless SSH credentials; minting other tokens; the in-panel Assistant chat; and the routes that mint browser logins into WordPress, phpMyAdmin, pgAdmin or webmail. These answer not_exposed. The full list, with the reasons, is in Safe operating rules.