Function to process only new entries on Get Http request

Hello,

Would you please help me fix the function node of the flow, I want to process only the new entries from the first get request, it should not process the same entry which it has previously processed when the flow runs next time after 15 minutes.

I’m new to n8n any help will be much appreciated.

Here is the code of my flow.

{
  "nodes": [
    {
      "parameters": {
        "interval": 15,
        "unit": "minutes"
      },
      "name": "Interval",
      "type": "n8n-nodes-base.interval",
      "typeVersion": 1,
      "position": [
        -2380,
        140
      ]
    },
    {
      "parameters": {
        "functionCode": "const staticData = this.getWorkflowStaticData('node');\n\nstaticData.count = staticData.count || 0;\nstaticData.count += 1;\n\n// Data can also be deleted again\n//delete staticData.count;\n\nitems[0].json.count = staticData.count;\n\nreturn items;"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        -1600,
        140
      ]
    },
    {
      "parameters": {
        "operation": "limit"
      },
      "name": "Item Lists",
      "type": "n8n-nodes-base.itemLists",
      "typeVersion": 1,
      "position": [
        -1850,
        140
      ]
    },
    {
      "parameters": {
        "authentication": "headerAuth",
        "url": "=https://api.teachworks.com/v1/lessons/?direction=desc",
        "options": {
          "splitIntoItems": true
        },
        "queryParametersUi": {
          "parameter": []
        }
      },
      "name": "Get Lesson",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        -2100,
        140
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "1",
          "name": "Header Auth account"
        }
      }
    },
    {
      "parameters": {
        "authentication": "headerAuth",
        "url": "=https://api.teachworks.com/v1/employees/{{$node[\"Item Lists\"].json[\"employee_id\"]}}",
        "options": {
          "splitIntoItems": false
        },
        "queryParametersUi": {
          "parameter": []
        }
      },
      "name": "Get Teacher",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        -1370,
        140
      ],
      "retryOnFail": true,
      "waitBetweenTries": 5000,
      "credentials": {
        "httpHeaderAuth": {
          "id": "1",
          "name": "Header Auth account"
        }
      }
    }
  ],
  "connections": {
    "Interval": {
      "main": [
        [
          {
            "node": "Get Lesson",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "Get Teacher",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Item Lists": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Lesson": {
      "main": [
        [
          {
            "node": "Item Lists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

n8n wouldn’t have that functionality built in, so you would need to implement the polling logic yourself. You can find a great tutorial at Creating triggers for n8n workflows using polling ⏲ that explains the basic concept. It’s refering to the Google Sheets node, but the concept can of course be applied to other data sources too.

Thank you so much @MutedJam you made my day!!

1 Like