N8N API doesnt work to stop a workflow

Hi everyone, I hope you can help me with the n8n API.

I’m running my server on a VPS. I downloaded Easy Panel and added some environment variables.

I tried using the API within a workflow, both with Basic Auth to access the UI and with an API created in the setting > n8n API.

I used https in get, and it gives me information with Basic Auth using the keys I put in my environment variable in Easy Panel. However, when I try to post to stop a workflow, it tells me “unauthorized.”

I’d like to know why the credentials aren’t working and if there’s a way to stop the workflow immediately upon receiving a webhook or an external request. I’ve tried the stop workflow nodes, but they don’t work because my workflow has many “waits,” so it takes a long time until it reaches the stop workflow node and doesn’t give any feedback on my website.

Hi @teo_dc

n8n’s public API requires authentication via an API key, not Basic Auth,

Name: X-N8N-API-KEY

In: header

You must generate an API key in Settings > n8n API and use it in your requests as a header or use in the n8n node

Hi dear,

I tried this and doesn´t work, i creared n8n api and use it to create credentials and to use with the n8n node and it works, but i want to stop a workflow and this n8n native node doesnt have this option.

So I tried with https request, with headers:

I tried that your recomended:
Name: X-N8N-API-KEY
Value: My_Api_key

None authentication, is that right? I tried with this url: https://my_url/rest/executions

I tried another way that work with this same url in a http request and headres like
Name: browse-id Value:….
Name cookies Value:….
It works a few of days, but i imagine that cookies change or renovate and now it isnt working anymore, and i cant change it forever cause is for a client.

The url that i used was https://my_url/rest/executions/{{ $json.id }}/stop

I don’t think this is supported by the n8n API endpoint..
You only have options to activate/deactivate a workflow and rety/delete for an execution..

Seems like you’re trying to mimic what the UI does, I haven’t actually tried that tbh..

okey, thank you.

so Do you know any way to stop a running or waiting execution with a request triggered from another workflow?

I have a webhook that fires when a cancel button is pressed, and I need the next node to stop the execution that was previously started.

Until there’s an official API /stop option for an execution, I’d handle it without using the API, just by using shared flags stored somewhere (You can use the new n8n feature Data Tables for this, this is a good use case IMO)

For example:

Workflow A (Main Workflow):

  • At the start of the workflow, store some useful information for later use, such as the execution ID and a my_state flag set to "started"
  • Before every major node (or wherever you prefer) add a Check my_state step:
    • Use an IF node to check the stored my_state
    • If it’s set to "stop", exit gracefully using a Stop and Error node

Workflow B (Stop Webhook):

  • Trigger: A webhook for “stop” that take the execution ID as a parameter
  • Find the related execution ID (stored earlier)
  • Update the shared flag (my_state) to "stop"

Hope this makes sense!
1 Like

Yes, that’s full sense. Thank you a lot, only one more things, my workflow has the option to prográmate date to trigger it, so maybe it could be two days waiting and if i cancel i need to wait two days if the nodo “If” is after.

I think that with the API, with delete executions the execution that’s are waiting are cancelled. Is it right? so with your solution y can cancel workflows running and with my option can stop workflows waiting.

Yes, using the /stop approach will immediately stop the execution at any node even while it’s running.

However, with the approach I explained, the execution will appear as “stop” in your UI, but in the background, it will continue running until it reaches a node that checks the stop condition..

In my opinion, this approach is better because it allows the execution to exit gracefully and finish any ongoing processes, while the frontend still shows it as stopped to the user.

Anyway, it’s up to you, just go with whatever suits your needs best..

if the excution status is waiting (using wait nodes) then you can use the delete excution endpoint.

if the excution status is running (nodes are running) then you cant use the delete excution endpoint, you will an error Cannot delete a running execution

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.