mockfly logo

Public API

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. You can also explore and run every request interactively in our Postman collection.

Authentication

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>"

Managing projects

Project operations use your account API key, since operations like creating or importing a project happen before any project exists.

Create a project

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.

Import a project

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:

Update a project

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"}'

Delete a 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.

Managing endpoints and responses

Endpoint and response operations use the project API key of the project they belong to:

MethodPathDescription
GET/public/endpointsList all the endpoints of the project
POST/public/endpointsCreate an endpoint
GET/public/endpoints/:endpointIdGet an endpoint
PATCH/public/endpoints/:endpointIdUpdate an endpoint
DELETE/public/endpoints/:endpointIdDelete an endpoint
POST/public/endpoints/:endpointId/responsesCreate a response
PATCH/public/endpoints/:endpointId/responses/:responseIdUpdate a response
DELETE/public/endpoints/:endpointId/responses/:responseIdDelete a response
POST/public/endpoints/:endpointId/responses/:responseId/duplicateDuplicate a response
PUT/public/endpoints/:endpointId/responses/:responseId/rulesReplace 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 full request and response examples for every route are available in the Postman collection.

Errors and limits

Errors are returned as JSON with a descriptive message:

{
  "error": "Error: Project not found"
}
StatusMeaning
401Missing, invalid or revoked API key
400Invalid payload or resource not found
403You are not the admin of the project
429Plan 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.