# Creating and Configuring Mocks

> A step-by-step walkthrough: open API Mocks, pick a project, create or bulk-generate mocks, configure static and dynamic responses with conditions and delays, and start the mock server.

Source: https://totalshiftleft.ai/help-center/product-documentation/creating-and-configuring-mocks

## Overview

This guide walks you through the **API Mocks** screens exactly as they appear in Shift Left Studio, from opening the module to serving a mock over HTTP. A **mock** is a saved fake response (a path + method + one or more configured responses) that the mock server returns so you can build and test against APIs that don't exist yet or aren't available.

Conceptual background: [Understanding mocks](/help-center/product-documentation/understanding-mocks). Explore the capability at [mock server](/features/api-protocols/mock-server).

## Before you begin

- You need a **project** with at least one **endpoint** if you want to link mocks to endpoints or bulk-generate them. If you have none yet, see [Import and discover endpoints](/help-center/product-documentation/endpoint-import-and-discovery).
- Mock creation is license-gated, and the number of mocks is capped on the Free edition (50). Professional and Enterprise are unlimited.
- No AI key is required — generation is built from your API schema, not an AI model.

## Step 1 — Open API Mocks and select a project

1. In the top navigation bar, click **Mocks**. (The **Mocks** item is highlighted while you're in the module.)
2. The **API Mocks** page opens with a one-line description explaining that mocks can replace real API calls during test execution or run as a standalone server.
3. Scroll to **Select a project** and click a project card (for example **Pet Store**). The mocks table for that project opens.
4. To switch projects later, use the **All projects** control at the top of the mocks view to return to the project picker.

## Step 2 — Choose how to create mocks

In the header above the mocks table you'll see these buttons:

- **Start Mock Server** — starts serving your active mocks (covered in Step 6).
- **Create Mock** (blue) — build one mock by hand.
- **Generate Mock** (purple, sparkle icon) — bulk-create mocks from your endpoints' schemas.

Use **Generate Mock** to seed many mocks quickly, then refine them; use **Create Mock** for one-off or standalone mocks.

## Step 3 — Bulk-generate mocks from endpoints

1. Click **Generate Mock**. A dialog titled **Generate Mocks** opens and loads your features and endpoints as a checkbox tree.
2. Narrow the list with the **Search features and endpoints…** box, or use **Select All** / **Deselect All**. Expand a feature to toggle individual endpoints; the feature checkbox toggles all of its endpoints at once.
3. Watch the counter — it reads **N of M endpoints selected**. You must select at least one, or you'll see *"Please select at least one endpoint to generate mocks for."*
4. Click the footer **Generate Mocks** button. For each endpoint, the response body is built deterministically from the endpoint's OpenAPI/JSON schema (WSDL example XML for SOAP, a data envelope for GraphQL) — no AI model is called.
5. **If a selected endpoint already has a mock**, a **Resolve Mock Conflicts** dialog appears. For each endpoint choose one of:
   - **Skip (keep existing)** — leave the current mock untouched (this is the default).
   - **Update existing** — overwrite the current mock with the freshly generated one.
   - **Create duplicate** — add a second mock (named with a `(Copy)` suffix).
   Use **Skip All / Update All / Duplicate All** to apply one choice to every conflict, then click **Continue**.
6. A progress indicator shows **Generating X of Y…**. When it finishes you'll see a summary such as *"Successfully generated mocks: 6 created, 2 updated, 1 skipped."* The new mocks appear in the table.

## Step 4 — Create a mock manually

1. Click **Create Mock**. The response editor opens.
2. Enter a **Name** (required) and an optional **Description**.
3. **Link to Endpoint (Optional)** — choose an endpoint from the dropdown to auto-fill and lock its **Path** and **Method** (SOAP endpoints also expose **SOAP Operation** and **SOAP Action**), or choose **None – Create Standalone Mock** and set them yourself:
   - **Path** — must start with a leading slash, e.g. `/api/users/:id`. If it doesn't, you'll see *"Path must start with a leading slash."*
   - **Method** — GET, POST, PUT, DELETE, PATCH, HEAD, or OPTIONS.
4. **Response Type** — choose **Static (Fixed JSON)** for a fixed body, or **Dynamic (Template with Variables)** for a body built at request time.
5. Configure one or more responses (see Step 5).
6. If you added more than one response, pick which one is returned when no conditions match using **Default Response**.
7. Click **Create Mock** (the button reads **Update Mock** when editing). The mock appears in the table.

## Step 5 — Configure a response

Each mock holds one or more named responses. Click **Add Response** to add another; use the trash icon to remove one. For each response set:

| Field | What it does |
|-------|--------------|
| **Status Code** | The HTTP status returned (100–599), e.g. 200, 201, 400, 404. |
| **Delay (ms)** | Optional latency before the response is sent — use it to exercise timeouts and slow paths. |
| **Conditions (Optional)** | Return this response only when the request matches. Click **+ Add Condition**, choose a field (e.g. `query.userId`, `headers.authorization`), an operator (**Equals, Contains, Regex, Exists, Not Equals, In, Greater Than, Less Than**), and a value. |
| **Headers (JSON)** | Response headers as a JSON object, e.g. `{"Content-Type": "application/json"}`. Must be valid JSON. |
| **Body / Template** | The response payload (see below). |

**Static body:** Enter valid JSON in **Body (JSON)** (or XML for SOAP). Two helpers speed this up — **Fill standard error** inserts an `{ error, code }` shape, and **Fill standard success** inserts a `{ message }` shape.

**Dynamic template:** Switch **Response Type** to **Dynamic**, then enter a **Template** using `{{ … }}` variables that resolve per request:

- Random/utility: `{{uuid}}`, `{{timestamp}}`, `{{date}}`, `{{randomInt}}`, `{{randomInt(100)}}`, `{{randomFloat}}`
- Echo the request: `{{request.query.param}}`, `{{request.headers.name}}`, `{{request.body.some.path}}`, `{{request.path.id}}`

Example template: `{"id": {{uuid}}, "name": "User {{randomInt}}", "requestedId": "{{request.query.id}}"}`.

## Step 6 — Start the mock server and call your mocks

1. Click **Start Mock Server**. Only **active** mocks are served.
2. The UI shows two base URLs — copy whichever fits your setup:
   - **Path-based (local / same server)** — no DNS needed; use it when the engine runs on your machine or the same server.
   - **Subdomain (centralized)** — use it when your company has DNS for a central engine (e.g. `*.{projectId}.mock.<your-domain>`). Ask your admin if unsure.
3. Open the **How to Use** panel for ready-to-copy **cURL**, **JavaScript (Fetch)**, **Python (requests)**, and **Node.js (axios)** snippets pointed at your mock.
4. Call the mock from your client — you should get the configured status, headers, and body back (after any **Delay**). If you get **404 "No active mock found"**, confirm the mock is **Active** and the path/method match; if you get **503 "Mock server not running"**, start the server.

## Manage the mocks table

- **Toolbar:** **Search mocks** (filter by name/path), **Grouping** (e.g. by feature), **Columns** (show/hide), and a **count** such as *Showing 8 of 8 mocks*.
- **Columns:** **Status** (Active/Inactive), **Mock name** + description, **Feature**, **Endpoint** (method badge + path), **Type** (static/dynamic), **Responses** (count), **Created**.
- **Row actions:** **Play** (test the mock with a sample request and see the status/headers/body without hitting the running server), **toggle** Active/Inactive, **Edit**, **Delete**.
- **Bulk actions:** select rows to **activate**, **deactivate**, or **delete** several mocks at once.

## Troubleshooting

- **"Please select at least one endpoint…"** — you clicked Generate Mocks with nothing selected; tick an endpoint first.
- **Mock not returned (404)** — the mock is inactive, or the request path/method doesn't match. Toggle it **Active** and verify the path.
- **Invalid JSON error on save** — the Body or Headers field isn't valid JSON. Fix the syntax (use the **Fill standard…** helpers as a starting point).
- **Reached your mock limit** — Free is capped at 50 mocks; deactivate/delete unused mocks or upgrade.

## Related articles

- [Understanding mocks](/help-center/product-documentation/understanding-mocks)
- [Endpoint management](/help-center/product-documentation/endpoint-management)
- [Test execution](/help-center/product-documentation/test-execution)
- [Understanding workflows](/help-center/product-documentation/understanding-workflows)

