Build a High-Fidelity Mock API in n8n
Working with third-party APIs or internal microservices is tedious. There are usage fees, account setup, and test credentials that expire, break, or end up in your repo.
Early in development, you're building the functionality that consumes the API, not the API itself. Setting up the real thing at that stage is dead weight. Live APIs also make edge cases hard to test, and your setup mutates: rotate a password, change a permission, or delete a record, and your tests break.
Mocking APIs isn't new. What's different here is control: custom scenarios, your own data, your own logic. This post shows how to build a mock in n8n.
This article also includes a full video walkthrough:
What you'll need
- An n8n setup. The minimum version is 2.3.6, the first release with AI Agent support. I'm running 2.44.6, the community version, in a Docker container.
- An API key for the n8n AI Assistant. The assistant's agents use it to call their model.
- An API to mock. For this demonstration, I mocked a portion of the Google Health API.
Why n8n instead of a script?
You could ask an AI agent to write a simple Python or Node server. That works, but n8n gives you things a script doesn't:
- Execution history. Every request and response is logged in a visual history you can inspect and replay. There's no logging code to write.
- Built-in data tables. Browse, edit, and reset your mock data in a UI instead of a JSON file or a database you have to set up.
- Visual logic. You can see the whole flow, so scenarios are easy to follow and tweak, even for teammates who don't write code.
- No server boilerplate. Webhook nodes handle routing and responses. There's no framework, no dependencies, and no restarts.
- Easy sharing. A workflow exports as a single JSON file.
- A built-in AI Assistant. It builds and modifies the mock inside the same tool. A generated script means copying, running, and debugging somewhere else.
What "high fidelity" means
A high-fidelity mock is faithful to the vendor's real API: the same message structure, the same error handling, and the same data requirements. When you switch to live endpoints, your application works with minimal or no changes. The goal is a mock so close to the real thing that going live is a URL swap.
Step 1: Configure the AI Assistant
In n8n, go to Settings → Assistant, where the settings for your agents live. The minimum setup is a model and an API key. The key can come from Anthropic, OpenAI, or a gateway such as OpenRouter. I used an OpenRouter key.
For the model, I chose DeepSeek 4. It's cost-effective, yet capable enough to build n8n workflows. You can use any model you like, but make sure it's capable enough to understand the concepts and avoid frequent mistakes.
Step 2: Find good documentation
Documentation is the key to a high-fidelity mock, and Google provides excellent documentation for its APIs. I mocked the version 4 project subscribers endpoints, which include the typical create, list, delete, and update operations. This part of the API is for adding subscribers to the Health service application you'd be developing.
Click into any method and you can see the required fields for the objects involved, along with JSON examples. The n8n agent reads this documentation to create the mock's workflows, data tables, and types.
Step 3: Prompt the assistant
Back in n8n, I opened the AI Assistant and asked it to read the Google API documentation and build a high-fidelity workflow, or workflows, that mock the API using data tables. Then I pasted in the URL of the documentation page.
The wording matters. I didn't ask for endpoints that return fake data. I asked for a mock faithful to the documentation, with its data stored in data tables.
Step 4: Watch it build
The agent started with the data tables, which serve as the backend data the API reads from and writes to. It then generated the webhooks and the workflows:
- The webhooks are the endpoints your application calls.
- The workflows hold the logic that runs and handles the data.
It produced register, list, update, and remove operations, each faithful to the real Google API.
Next, the agent was ready to test its own endpoints, and I gave it permission to run them. As it worked, it reported the issues it found and the corrections it made so the endpoints behaved as expected.
When the first pass was complete, there were webhooks and workflows for every endpoint I'd asked for. The workflows have to be published before they can be used, so the agent asked whether to publish them. I agreed.
Step 5: Test it yourself
I asked the agent for curl commands to test the list endpoint and ran one in a Bash shell. Two problems came up. The output was piped to jq, which I don't have installed, and the agent had gotten the request payload wrong. After correcting both, I asked for a full set of curl commands covering every method on every endpoint.
I pasted those into my shell one at a time and reviewed each response. They matched what I expected, so the API worked.
What makes n8n a good home for mocks
With the endpoints tested, a few n8n features are worth a closer look:
- Publish status. The workflows list shows which workflows are published. In this case, all of them were.
- Visible logic. Open a workflow and expand an endpoint, and you can see the nodes that make up the mock's logic and flow.
- Executions. For every call, you can inspect the request, response, headers, and variables at each stage.
- Data tables. The mock's data is driven by n8n data tables, so you control the data the vendor would normally control. That lets you test invalid data and edge cases, and steer the mock toward the behavior you need. The clients you write get a faithful stand-in for a live production API.
Takeaways
- Mocking lets you build and test the consuming code without usage fees, account setup, or expiring credentials.
- n8n gives you execution history, editable data tables, and visible logic, with no server code to maintain.
- The quality of the mock depends on the quality of the documentation you give the assistant.
- Because the mock follows the vendor's real structure, errors, and data rules, you can build against it today and switch to live endpoints with minimal or no changes.
Try it on an API you work with. Point the assistant at the documentation and see what it builds.