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