How to Mock and Monitor API Calls in n8n in Docker

Debugging n8n workflows can be complex yet rewarding. This article guides you through effective debugging techniques, including tracing API calls and using logging streaming. By configuring Proxyman in Docker, you can monitor requests efficiently. Learn to mock and test your workflows to ensure t...

How to Mock and Monitor API Calls in n8n in Docker

Workflows in n8n can be incredibly powerful, but they can also be complicated at times. As with any software system, good debugging skills are essential.

In this article, we'll look at how to effectively debug your n8n workflows.

Let’s dive in.

Let's say you're running a workflow with some API calls and you're not getting the results you expected. You can trace the call and look in the Chrome console to see the request like this:

You can also use logging streaming as described here. Please note that this feature is only available in the paid version.

Once you've identified the error, you may need to iterate through the workflow several times. If you're using APIs, this can get expensive, so mocking and monitoring requests is incredibly important for building your workflows quickly and cost-effectively.

Configuring Proxyman with Docker

If you run Proxyman on the host and n8n on the same machine, it may work out of the box if Proxyman is configured correctly, as n8n would automatically pick up the system proxy. However, if you run it in a Docker container (and even worse, on a Mac), it can become cumbersome. So you need to explicitly tell the n8n container to use the Docker host proxy (Proxyman) when it starts.

You would then extend the Docker command like this. Note that you'll need to update your host's proxy port accordingly (by default it's 9090, but I use 9091 because 9090 is in use):

docker run -d -it \
  --name n8n \
  -p 5678:5678 \
  -v n8n_data:/home/node/.n8n \
  --env HTTP_PROXY=http://host.docker.internal:9091 \
  --env HTTPS_PROXY=http://host.docker.internal:9091 \
  --env NO_PROXY=localhost,127.0.0.1 \
  --add-host=host.docker.internal:host-gateway \
  docker.n8n.io/n8nio/n8n

Once that is done, the rest is easy. To set up the mock and trace the request, you need to follow these steps:

First, create a local map (aka mockup) and activate it.

Create Local Map


Activate Mockup

Next, enable your proxy to listen on the specified port that you configured when you started your Docker container.

Enable Proxy

Optionally, add a filter for the request you want to monitor.

Add Filter

Testing it

Test it using any HTTP request node inside your n8n instance (running in Docker). Hit the test step.

Test Step

Finally, you should be able to see the request and response in Proxyman.

Request and Response

That's it.

Using this approach, you can debug and mock as many API calls as you like. When you have enough confidence, just turn off Proxyman and run on the live server and pray 😄.