How to create multiple tasks in Clickup?

Describe the problem/error/question

I’ve created a workflow that creates a folder and a list in Clickup, then gets all tasks from a “template” list and creates new tasks in the freshly created list based on the template tasks (because there’s no API endpoint for using a list template). This works fine when I hardcode the list ID in the task creation node, but if I refer to the list with {{ $node['post-list'].json.id }}, it shows up correctly in the UI but on execution only one task is created and then I get an error “List ID invalid”.

Am I correct in assuming the list ID should be available during the entire loop, not just the first item?

What is the error message (if any)?

List ID invalid

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 0.226.2
  • Database (default: SQLite): MySQL
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Amazon Linux 2

Hi @akallio, welcome to the community :tada:

Based on your description I suspect the number of items you’re processing could change between your nodes. This is likely to cause the problem when using an expression of {{ $node['post-list'].json.id }}:

For the first item your node receives, this expression would read the id value from the first item on the post-list node which is fine. For the second item it would read the id value from the second item on the post-list node and so on.

Now if your post-list node has only one item, there would be no value for all subsequent items on your current node. This means n8n would send an empty value to Clickup, and thus causing an error.

In such cases you can use an expression of {{ $('post-list').first.json.id }} to always read the first item from your post-list node. If your post-list node would have multiple items, you could try using {{ $('post-list').item.json.id }} instead which makes use of item linking to identify the correct corresponding item.

You can find a full list of the available variables and methods in our documentation at Built in methods and variables reference - n8n Documentation.

Hope this helps :slight_smile:

2 Likes

Hi @MutedJam, thanks for the reply!

I actually thought of this, and tried using first(), but the editor doesn’t let me use first() since the node doesn’t return multiple items, therefore $('post-list') isn’t an array. $('post-list').first doesn’t exist.

Is there a way to set the value of $('post-list').json.id to a workflow context variable, which could be then injected to each item after the get-tasks-template node with the “set” node? Or can I use some other reference to explicitly force the item loop to refer to a single value on each iteration?

Hi @akallio, I’m so sorry. This was a typo on my side, it should be .first() with the empty parenthesis, so {{ $('post-list').first().json.id }}

This should work in n8n:

image

1 Like

Hi,

@MutedJam, that worked! I actually confused $('nodeName') and $node['nodeName'] syntaxes, and only the first returns single items as array, the second ones throws an error first() is only callable on type "Array".

This resolves my issue, thank you for the great support!

3 Likes

Glad to hear this helped, thank you so much for confirming!

Seems like we’ll switch to the $(‘nodeName’) syntax as a default option soon, so hopefully this will become less confusing.

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