How to get new RSS item?

Question

How to get new RSS item?

When i run this code, I’m receive all items. every times.

I want receve new item only.
like this https://ifttt.com/applets/dT7vx4JY-rss-to-gmail

Code

{
  "nodes": [
    {
      "parameters": {
        "url": "http://example.com/rss"
      },
      "name": "RSS Feed Read",
      "type": "n8n-nodes-base.rssFeedRead",
      "typeVersion": 1,
      "position": [
        400,
        450
      ]
    },
    {
      "parameters": {
        "fromEmail": "[email protected]",
        "toEmail": "[email protected]",
        "text": "={{$node[\"RSS Feed Read\"].data[\"title\"]}}\n{{$node[\"RSS Feed Read\"].data[\"link\"]}}",
        "html": "="
      },
      "name": "Mailgun",
      "type": "n8n-nodes-base.mailgun",
      "typeVersion": 1,
      "position": [
        550,
        450
      ],
      "credentials": {
        "mailgunApi": "my_mailgun"
      }
    },
    {
      "parameters": {
        "triggerTimes": {
          "item": [
            {
              "mode": "everyX",
              "value": 10,
              "unit": "minutes"
            }
          ]
        }
      },
      "name": "Cron",
      "type": "n8n-nodes-base.cron",
      "typeVersion": 1,
      "position": [
        250,
        450
      ]
    }
  ],
  "connections": {
    "RSS Feed Read": {
      "main": [
        [
          {
            "node": "Mailgun",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Cron": {
      "main": [
        [
          {
            "node": "RSS Feed Read",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Welcome to the community!
Yes, the node simply returns all the items it finds. The filtering out of already processed items has to be done manually. That means you have to save the date of the last processed item and then remove all the ones before that date. It is possible to save that value in multiple ways, the easiest is with the static data. Here an example workflow:

{
  "nodes": [
    {
      "parameters": {
        "url": "https://www.nasa.gov/rss/dyn/breaking_news.rss"
      },
      "name": "RSS Feed Read",
      "type": "n8n-nodes-base.rssFeedRead",
      "typeVersion": 1,
      "position": [
        450,
        450
      ]
    },
    {
      "parameters": {
        "fromEmail": "[email protected]",
        "toEmail": "[email protected]",
        "text": "={{$node[\"Function\"].data[\"emailText\"]}}"
      },
      "name": "Mailgun",
      "type": "n8n-nodes-base.mailgun",
      "typeVersion": 1,
      "position": [
        1250,
        550
      ],
      "credentials": {
        "mailgunApi": ""
      }
    },
    {
      "parameters": {
        "triggerTimes": {
          "item": [
            {}
          ]
        }
      },
      "name": "Cron",
      "type": "n8n-nodes-base.cron",
      "typeVersion": 1,
      "position": [
        250,
        450
      ]
    },
    {
      "parameters": {
        "functionCode": "const staticData = this.getWorkflowStaticData('global');\n\nlatestRead = staticData.latestRead;\n\nfor (let item of items) {\n  item.json.latestRead = latestRead || '1970-01-01';\n}\n\nreturn items;"
      },
      "name": "Latest Read",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        650,
        450
      ]
    },
    {
      "parameters": {
        "functionCode": "const staticData = this.getWorkflowStaticData('global');\n\nif (items.length > 0) {\n  staticData.latestRead = items[0].json.isoDate || staticData.latestRead;\n}\n\n\nreturn items;"
      },
      "name": "Write Latest Read",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1050,
        350
      ]
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{new Date($node[\"Latest Read\"].data[\"latestRead\"]).getTime()}}",
              "value2": "={{new Date($node[\"RSS Feed Read\"].data[\"isoDate\"]).getTime()}}"
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        850,
        450
      ]
    },
    {
      "parameters": {
        "functionCode": "let emailText = '';\n\nfor (let item of items) {\n  emailText += `${item.json.title}\\n${item.json.link}\\n\\n`;\n}\n\nreturn [{json: {emailText}}];"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1050,
        550
      ]
    }
  ],
  "connections": {
    "RSS Feed Read": {
      "main": [
        [
          {
            "node": "Latest Read",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Cron": {
      "main": [
        [
          {
            "node": "RSS Feed Read",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Latest Read": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          },
          {
            "node": "Write Latest Read",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "Mailgun",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

It is, however, important to remember that the static data does not get read and written when testing via the Editor-UI. So every time you test it will use the in the node defined default date and will to always return all items. If you then, however, activate the workflow it will work like intended. You can test that easily by setting the cron-time to something short like 1 minute. You will then see that the first time it runs it will send an email with all items and the second run, it will not send an email at all (unless by accident a new item gets added in the meantime).

1 Like

Btw. here the documentation about the static data:
https://docs.n8n.io/#/nodes?id=method-getworkflowstaticdatatype

1 Like