Mockfly provides a public REST API so you can manage your projects, endpoints and responses programmatically: create projects from a script, import a whole project from your CI pipeline, or keep your mocks in sync with your codebase without opening the dashboard.
The base URL for all requests is https://api.mockfly.dev.
The whole API is also described by a machine-readable OpenAPI 3.1 specification:
https://mockfly.dev/openapi.jsonPoint a client generator, an IDE or an AI agent at that URL and it gets every operation, its parameters, its request and response schemas and its error codes without having to read this page. If you prefer to explore and run the requests interactively instead, the Postman collection covers the same API.
All requests require the Authorization header with an API key as its raw value (no Bearer prefix). There are two types of API keys, depending on what you want to do:
curl https://api.mockfly.dev/public/projects \
-H "Authorization: <your_account_api_key>"Project operations use your account API key, since operations like creating or importing a project happen before any project exists.
curl -X POST https://api.mockfly.dev/public/projects \
-H "Authorization: <your_account_api_key>" \
-H "Content-Type: application/json" \
-d '{"name": "My project", "tags": [{"name": "backend", "color": "#48cfad"}]}'name is required, tags is optional. The response includes the new project with its slug and its project API key.
Creates a project together with all its endpoints and responses in a single call. The payload is the same JSON produced by the dashboard's "Export to JSON" feature, so you can export an existing project and re-import it programmatically. See Import Project from JSON for the full payload structure and field descriptions.
curl -X POST https://api.mockfly.dev/public/projects/import \
-H "Authorization: <your_account_api_key>" \
-H "Content-Type: application/json" \
-d '{
"project": {"name": "Imported project"},
"endpoints": [
{
"path": "/users",
"method": "GET",
"responses": [
{"name": "OK", "status": 200, "body": {"users": []}, "isEnabled": true}
]
}
]
}'A few things to keep in mind:
path, method and a responses array (empty is allowed).bodyExample and each response body must be JSON objects or arrays, not strings.curl -X PATCH https://api.mockfly.dev/public/projects/:projectId \
-H "Authorization: <your_account_api_key>" \
-H "Content-Type: application/json" \
-d '{"name": "Renamed project"}'curl -X DELETE https://api.mockfly.dev/public/projects/:projectId \
-H "Authorization: <your_account_api_key>"Only the project admin can update or delete a project.
Endpoint and response operations use the project API key of the project they belong to:
| Method | Path | Description |
|---|---|---|
| GET | /public/endpoints | List all the endpoints of the project |
| POST | /public/endpoints | Create an endpoint |
| GET | /public/endpoints/:endpointId | Get an endpoint |
| PATCH | /public/endpoints/:endpointId | Update an endpoint |
| DELETE | /public/endpoints/:endpointId | Delete an endpoint |
| POST | /public/endpoints/:endpointId/responses | Create a response |
| PATCH | /public/endpoints/:endpointId/responses/:responseId | Update a response |
| DELETE | /public/endpoints/:endpointId/responses/:responseId | Delete a response |
| POST | /public/endpoints/:endpointId/responses/:responseId/duplicate | Duplicate a response |
| PUT | /public/endpoints/:endpointId/responses/:responseId/rules | Replace the conditional rules of a response |
For example, to create an endpoint:
curl -X POST https://api.mockfly.dev/public/endpoints \
-H "Authorization: <your_project_api_key>" \
-H "Content-Type: application/json" \
-d '{"projectId": "<your_project_id>", "path": "/users", "method": "GET"}'The request and response schemas for every route are described in the OpenAPI specification, and the Postman collection has a runnable example for each of them.
Errors are returned as JSON with a descriptive message:
{
"error": "Error: Project not found"
}| Status | Meaning |
|---|---|
401 | Missing, invalid or revoked API key |
400 | Invalid payload or resource not found |
403 | You are not the admin of the project |
429 | Plan limit exceeded |
Free plan limits also apply through the API: 1 project as admin, 4 endpoints per project and 2 responses per endpoint. Upgrade to premium to remove these limits.