n8n-io / n8n

Free and source-available fair-code licensed workflow automation tool. Easily automate tasks across different services.
https://n8n.io
Other
46.53k stars 6.69k forks source link

Workflows Public API Tags Parameter Does Not Support Multiple, Comma Separated, Tags #10348

Closed rthomas67 closed 1 month ago

rthomas67 commented 1 month ago

Bug Description

Response from /api/v1/workflows only works with a single tag value for the tags query parameter.

Observed

Expectation Based On...

Theory

Maybe typeorm doesn't behave as expected here: https://github.com/n8n-io/n8n/blob/master/packages/cli/src/databases/repositories/tag.repository.ts#L65

To Reproduce

  1. Create a few workflows in an api-reachable n8n instance
  2. Tag one of the workflows with a tag named test_tag_1, and the other with test_tag_2
  3. Using VSCode REST Client plugin, replace hostname:port (if necessary), and api key header values, and run each request from this file.
    • The third one does not work.
      
      ###
      GET http://n8n:5678/api/v1/workflows?tags=test_tag_1
      X-N8N-API-KEY: n8n_api_7796d24...replace-me

GET http://n8n:5678/api/v1/workflows?tags=test_tag_2 X-N8N-API-KEY: n8n_api_7796d24...replace-me

GET http://n8n:5678/api/v1/workflows?tags=test_tag_1,test_tag_2 X-N8N-API-KEY: n8n_api_7796d24...replace-me



Or... 

1. Do steps 1 and 2 from above, and...
2. Import the attached workflow with various test nodes.
    * [n8n_get_many_workflows_bug.json](https://github.com/user-attachments/files/16575653/n8n_get_many_workflows_bug.json)
3. Assign the n8n credential item where required.
4. Run the workflow and observe results.

### Expected behavior

Passing a "comma separated list of tags," per documentation, to the /api/v1/workflows API function's **tags** parameter, **should** return all workflows matching **any** of the tags.

BTW, it is also unclear how the **tags** parameter value would be constructed to specify **tag names _containing_ commas,** spaces, or other special characters, which does not seem to be prohibited in n8n's tag-creation/naming UI.

### Operating System

6.1.0-rpi4-rpi-v8 #1 SMP PREEMPT Debian 1:6.1.54-1+rpt2 (2023-10-05) aarch64 GNU/Linux + Docker version 20.10.24+dfsg1, build 297e128 + Image: n8nio/n8n:1.50.1

### n8n Version

1.50.1

### Node.js Version

v20.15.0

### Database

PostgreSQL

### Execution mode

main (default)
Joffcom commented 1 month ago

Hey @rthomas67,

We have created an internal ticket to look into this which we will be tracking as "GHC-148"

Joffcom commented 1 month ago

Hey @rthomas67,

I have just tried to reproduce this on 1.54.0 and it appears to be working as expected

curl https://n8n.mydomain.com/api/v1/workflows\?tags\=testing,allowPreview -H "X-N8N-API-KEY:n8n_api_XXXXX"

{"data":[{"createdAt":"2024-08-12T06:38:16.343Z","updatedAt":"2024-08-12T06:39:18.778Z","id":"ggv4I52wgfXUBEsw","name":"My workflow 138","active":false,"nodes":[{"parameters":{},"type":"n8n-nodes-base.manualTrigger","typeVersion":1,"position":[940,420],"id":"696affd8-ee48-48d2-a89b-80d0b02486f8","name":"When clicking ‘Test workflow’"},{"parameters":{"filters":{"tags":"testing,allowPreview"},"requestOptions":{}},"type":"n8n-nodes-base.n8n","typeVersion":1,"position":[1140,420],"id":"c9c22029-3d8b-4565-b331-0eaf5dd16e8e","name":"n8n","credentials":{"n8nApi":{"id":"t2YEgbUMXHjsykeF","name":"admin"}}}],"connections":{"When clicking ‘Test workflow’":{"main":[[{"node":"n8n","type":"main","index":0}]]}},"settings":{"executionOrder":"v1"},"staticData":null,"meta":null,"pinData":{},"versionId":"ac791b12-2f85-46c9-b2e2-276906e95d62","triggerCount":0,"tags":[{"createdAt":"2022-07-07T05:46:15.052Z","updatedAt":"2022-07-07T05:46:15.052Z","id":"14","name":"testing"},{"createdAt":"2023-03-28T16:39:50.917Z","updatedAt":"2023-03-28T16:39:50.917Z","id":"86","name":"allowPreview"}]}],"nextCursor":null}

I have also given it a quick go in Postman as well.

image

Would you be able to try updating your n8n version to see if this is something that has been fixed in a later version. It may also be worth noting it is workflows containing both tags not either of the tags.

With tags containing a comma I can't work out a way to make that work so that will need to be passed to the the team to look at but if you can check the update first we can make the ticket a lot smaller.

rthomas67 commented 1 month ago

@Joffcom, as you suggest, if a workflow is assigned all-of the tags in the specified CSV list, it is selected, even in the version I was testing.

So, this is probably due to a difference in assumptions about vaguely documented behavior. IMO, based on the current documentation, most people would expect the CSV list of tags to result in the inclusion of all workflows matching any-of the tags, not only workflows matching all-of the tags.

Thank you for clarifying how n8n is actually behaving. I'm sure your comments on this issue will help others who made the same any-of assumption I did.

So, now that that is settled, could we turn this into a feature request? It would be loads more useful to me to have an any-of option for tags. The current all-of behavior does not apply to any use case I can think of, since that would suggest the need to apply 2 or more tags to a given workflow in order for it to be selected by a specified CSV list of tags on the n8n-node / API request. In other words, the behavior I want here is that adding more tags in the CSV list would include/match more things (e.g. include workflows tagged with "test" OR "production").

rthomas67 commented 1 month ago

Until there is a direct, single call, option to fetch all workflows matching any-of the tags in a CSV list, this is the best workaround I could dream up so far: https://community.n8n.io/t/processing-csv-items-one-by-one/51665

Joffcom commented 1 month ago

Hey @rthomas67,

It can be made a feature request, We handle those through our support forum and we only use GitHub for bugs. I do agree the documentation could be improved on to make life a lot easier there.

I have created the feature request here: https://community.n8n.io/t/public-api-tags-should-be-or-not-and/51701 feel free to pop a vote on it so we can see what the community think about the idea, Personally I think it makes to have an option to change between or and and so you can do either.

For now as there is no bug here I will mark this as solved, Let me know if you have any other questions on this.