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: