N8n Reddit createComment node only processes first item (‘things’ undefined’)

I have an n8n workflow that:

  1. Scrapes Reddit posts
  2. Filters out posts older than 12 hours or not marked “Relevant”
  3. Drafts a comment with OpenAI
  4. Appends each item to Google Sheets
  5. Retrieves the row and posts the comment back to Reddit

When I supply a list of, say, 10 posts/URLs, the workflow only ever posts one comment and then stops. I’m trying to loop over all items, but I get an error about an undefined variable called things in the Create a comment in a post node.

Beyond that, I also want to:

  • Filter out locked Reddit posts (i.e. don’t attempt to comment on posts where comments are locked)
  • Automatically remove duplicates from my Google Sheet so I never post the same link twice
  • Only post new items on each run (i.e. rows added in the last execution, not older rows)
  • Keep the workflow running automatically, without manually triggering it, so it continually picks up new posts

Describe the problem/error/question

When I supply a list of, say, 10 posts/URLs, the workflow only ever posts one comment and then stops. I’m trying to loop over all items, but I get an error about an undefined variable called things in the Create a comment in a post (Reddit) node.

What is the error message (if any)?

Cannot read properties of undefined (reading 'things')

This error occurs in the Create a comment in a post node. If I enable Continue on Fail, the workflow runs without crashing but still only processes the first item

Please share your workflow

Add an If node before Create a comment in a post that checks that the ID field exists and that the post isn’t locked. If Reddit returns a locked: true field in the post’s JSON, use it.

Enable Continue on Fail. Although you’ve already set this up for some nodes, I recommend making sure it’s enabled specifically for Create a comment in a post. This prevents a single item error from interrupting the entire batch.

Hi Erick,

Thank you for your response. I don’t actually have a locked flag or any json.locked variable, it’s coming back as undefined. And even with Continue on Fail enabled on the Create Comment node, it still aborts.

I get the same error… Let me know if you’ve solved it

Hello @kent, try to add “pairedItem”: 1 right below the json key in your code, so it will be look like this

return items[0].json.data.children.map(child => {
  return {
    json: {
      display_name: child.data.display_name
    },
    pairedItem: 1
  };
});

Hello,

Thank you for your response! I still get the same error though. :frowning:

Use SplitInBatches before posting. Add a SplitInBatches node just before the Create a comment in a post node:

  1. Get row(s) in sheet
  2. SplitInBatches (batchSize: 1)
  3. Create a comment in a post

This ensures that the Reddit node processes them one by one and not all at once.

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