Conditional For Loop with data merge

Describe the problem/error/question

I’m running into an issue with my workflow where i’m trying to post a twitter thread I wrote on notion that is composed of a cell that has JSON. I parse the JSON and then I post the first tweet and reply to every next tweet thereafter, only when there’s a twitter id that exists and then I “Reply To” = ID

The problem: When I execute the workflow, it only runs once or experiences strange behaviour that is inconsistent like running them without the ID. I did a few variations, but none of them had consistent behaviour.

I’m wondering if anyone has resolved an issue like this that relies on data created within the loop. Is this where environment variables come into place? I’d like to keep it self contained since I don’t need the data anywhere else.

What is the error message (if any)?

Please share your workflow

Share the output returned by the last node

I am expecting “N” tweet posts which respond to each of the next threads.

Information on your n8n setup

  • n8n version: ai-beta 1.14.0
  • Database (default: SQLite): default
  • n8n EXECUTIONS_PROCESS setting (default: own, main): own
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: macOS

Hi @esturban, welcome to the community though I am sorry you’re having trouble!

From looking at your workflow I am not quite sure what exactly you expect here. The loop node would only be called once in your example, so has no real function. The actual loop you have built would go through the Merge node and I am having a hard time wrapping my head around what the expected behaviour is.

Assuming you are having an array of texts you’d like to post I don’t think you’d need any loop here. Twitter/X no longer let me access their API, so I can’t post a full example, but the basic workflow could look like so:

n8n will separate the incoming data into the first item and all other items. It then posts the first item, before using the Merge node to attach the id field from the response to all remaining items. The remaining items are then posted in the last step.

This should of course work with X in pretty much the same way as my HTTP Request node, though you might need to adjust the field names accordingly.

Hope this makes sense and helps :slight_smile:

Hi @MutedJam, the purpose is to create a thread of tweets where the first one begins as the tweet initiating the thread and then every tweet thereafter is posted in reply to the next.

So if I have an array of 10 tweets,
The first tweet is the original post
and then the second tweet replies to the first
and then the third tweet replies to the second
and so on until 10 are posted.

This can be done easily in Python and the example could actually be found here: TwitterThreadsAPI/ at main · MikeBorman1/TwitterThreadsAPI · GitHub

However, i’d be curious to make this work through n8n.

If you have an idea on how to do something like this, please let me know. I feel like i’d need a data store or some type of hosted variable

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