Control N8N API from N8N

I am making a subagent that gets a list of workflows, activates/deactivates workflows from my main agent.

I want my agent to get the workflow ID from the first tool, then pass it to the other tool. I tried using $fromAI but it did not work.

How do I go about setting this up.

Information on your n8n setup

  • n8n version:1.81.4
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Digital ocean, Docker Compose):
  • Operating system: Ubunty

Not sure I understood completely. You want the “Get Workflow” node to use a workflowID from a previous node? Because looking at the node I don’t see any parameters passed to it.

Hi crisl,

getworkflow is supposed to get all workflows. I limited them by “tags” to avoid returning all my unused workflows.

When that list of workflows, their ids, is back. I want to instruct the agent to “Activate x workflow”. Here is where the second tool “activate workflow” should get the ID, and send the post request to activate that workflow.

Ok, let me set up your workflow on my machine to play around. Will get back to you.

The idea of putting the http node first, is to let the AI agent always have a snapshot of the workflows without him needing to request it.

first tip, don’t put the API credentials in the header. You can use the predefined credential type for n8n and just add your key to the credentials. This will also keep them safe when copying to the forum or somewhere else.

Now to the actual question, I created your workflow and expanded it by another workflow.
I first created a workflow that would activate the requested workflow

This would just take the workflow ID from the passed in parameter and activate that workflow.

This tool would then call the second workflow to activate the requested workflow, you would just need to duplicate the workflow for deactivation or pass in an “action” parameter and catch it with an if statement to decide if an activation or deactivation was requested.
Hope this helps.

Thank you,

What type of Auth does n8n work with? I’m assuming header auth?

Yes it uses header auth and if you define it in the credentials you can use it for custom http requests that target n8n and as well as n8n nodes. This also means that if you change the credential for some reason you have a single place where you need to update it.
Of course also being encrypted would be a very strong reason to save it as credential and not as plain header.

So in that workflow, what should i keep, the http node or the getworkflow tool?

And is there a way to create it as a tool in the same workflow, not as a workflow tool that points to another?

Just to keep things simple and organised.

Honestly I wouldn’t. When asking via chat “what workflows are active” it will fetch the active ones anyway so the snapshot doesn’t really help here.

Since there is no n8n agent node, you could use the http request node as you already did for the activation / deaktivation then it would all be in one workflow.
I however prefer to have the workflows as minimal as possible and this would help me debug things if I only need to concentrate on one thing.
For example I could play with the activation workflow without needing to go through the AI Chat and once I’m happy with the way the workflow works give it one last try through the AI Chat.

2 Likes

Thank you crisl

I switched workflows, but now I’m getting a 404 while getting workflows:

HTTP 404 There was an error: “The resource you are requesting could not be found”

PS: I’m selfhosting on the cloud. What should my n8n API base url be in the credential?

your base url should be the URL of your instance what you also use for logging in.
If you are using n8n.example.com to access your n8n, then this is also the Baseurl you need to use.

yeah something definitely changed.

it’s not working anymore.

This was my 2 march execution

and now it give me this:

i literally copied the same workflow from this execution.
Even created 2 new APIs

What happened, did they change the get calls?

could you expand the “From HTTP Request” and “Other Info” in the http node?
It’s still working for me.
While this has nothing to do with your issue, you could change the authentication to a credential as described here then paste the workflow and I could put it on my test instance and give it a try again.

second photo is a test with a wrong API.

Results of both tests (photo1 and photo2) in n8n logs:

404 - “\n<html lang="en">\n\n<meta charset="utf-8">\nError\n\n\n

Cannot GET /api/v1/workflows
\n\n\n”

401 - “{"message":"unauthorized"}”

I really can’t see why it would not work.
Here’s my workflow, just tried it and still works.

I just restarted my n8n/caddy stack, and now it’s working.

I don’t know what was wrong, no settings changed.

Thank you crisl

1 Like

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