Google calendar Node; How I can fetch just new Events for last 24 hours?

I need just Google Calendar’s new event, they created in last 24 hours, for my 10 accounts, and combine it to one list,
Then I can sort the list by the time(Hours), and delete Duplicated Events to have just unique Events of the 10 accounts (in last 24 hours), Then I can send message to Slack node using these events email addresses.
The problem is, How I can set last 24 hours in “Google Calendar Node”, to get just newe Created events, not all events! (I do not want to getAll events -I mean more than 300 fields- of data from Google server - 10 times).

You can use the Start time parameter. It’s located under options. Did you try that?

1 Like

Yes, but I need fetch the events created in last 24 hours not eventa starting in last 24 hours. Just fetch by created time.

Hi @Saeid_Khoorani1, from taking a quick look at Google’s Calendar API documentation, it seems they do not support filtering by created date when listing events (which is what n8n does).

In many cases, the created timestamp of an event will however match the updated timestamp (and created can never be after updated). So my suggestion would be to fetch events updated in the last 24 hours through the Google Calendar node and then afterwards use an IF node to see which of the events found were created in the last 24 hours.

Example Workflow
{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "operation": "getAll",
        "calendar": "mutedjam",
        "options": {
          "updatedMin": "={{$json[\"yesterday\"]}}"
        }
      },
      "name": "Google Calendar",
      "type": "n8n-nodes-base.googleCalendar",
      "typeVersion": 1,
      "position": [
        680,
        300
      ],
      "credentials": {
        "googleCalendarOAuth2Api": {
          "id": "66",
          "name": "mutedjam"
        }
      }
    },
    {
      "parameters": {
        "action": "calculate",
        "value": "={{new Date()}}",
        "operation": "subtract",
        "duration": 24,
        "timeUnit": "hours",
        "dataPropertyName": "yesterday",
        "options": {}
      },
      "name": "Calculate 24 hrs ago",
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 1,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "dateTime": [
            {
              "value1": "={{$json[\"created\"]}}",
              "value2": "={{$items(\"Calculate 24 hrs ago\")[0].json[\"yesterday\"]}}"
            }
          ]
        }
      },
      "name": "Created less than 24 hrs ago?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        900,
        300
      ]
    },
    {
      "parameters": {},
      "name": "Recently created events",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1120,
        200
      ]
    },
    {
      "parameters": {},
      "name": "Old events",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1120,
        400
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Calculate 24 hrs ago",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Calendar": {
      "main": [
        [
          {
            "node": "Created less than 24 hrs ago?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate 24 hrs ago": {
      "main": [
        [
          {
            "node": "Google Calendar",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Created less than 24 hrs ago?": {
      "main": [
        [
          {
            "node": "Recently created events",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Old events",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
1 Like

Hi @MutedJam and thanks for the feedback.

The issue is about the amount of data that is fetched from Google calendar’s server is so huge amount!

I have more than 10 accounts, and if I want to fetch all events from all of these 10 accounts, I will get a huge amount of data in my workflow, and by the experience, the n8n Docker permanently stops and goes down! and I need to go to my server to start it again!

Then the straightforward way is to send the process to the Google server to pick just today’s events and send it to my Workflow, instead of getting all data and doing process and filters in Workflow.
The issue is How I can say to the Google server to pick just today’s events by created date, not start date!

This would be a feature request for Google I am afraid seeing they do not allow this kind of filtering right now. The aforementioned suggestion would, however, already reduce the amount of data (seeing you already filter some results out), so might be worth trying as a first step.

Just out of curiosity and to better understand your use case, how many calendar events are you processing? A time span of 24 hours returned around 70 events for me for a single calendar and memory consumption (read via docker stats) didn’t increase noticeably.

1 Like

I just used and started the workflow you recomended! But the result is not true!
I have more that one event in 12-2021.

What do you mean by “not true”? Is the timestamp returned by the first Date & Time node wrong? Did you by any chance set a limit in the Google Calendar node preventing all matches from being returned?

Which created and updated timestamps would an example event created in the last 24 hours look like for you that is not returned by the above example?

I mean the result is not true, by the calendar I have!
I have at least one event in last 24 hours, it should be in the list, but the result is undefined!

The JSON I am getting for all 10 accounts is more than 10,000 events!

This seems to be a very different result than what you have shared in your previous picture.

Seeing the error complains about an “undefined” value my guess is that one of the two expressions is referring to data that doesn’t exist for all items.

So that would mean either the the created field is missing from one of the input items of the IF node or that {{$items("Calculate 24 hrs ago")[0].json["yesterday"]}} doesn’t work in all circumstances in your specific workflow. You can easily rule out the latter by replacing the expression from the Value 2 field with a hardcoded timestamp from 24 hours ago. If that’s the case, did you by any chance change the workflow I have shared?

1 Like

In my opinion, let’s assume this solution works on an updated date, but the main issue is still not solved! I mean fetch order By created Date, not updated date!

As per the Google documentation I have linked above, fetching events filtered by their created is not something supported by the Google Calendar API unfortunately. So filtering by created would have to happen after fetching the events and the n8n way of doing this would be through the IF node.

It means I should get all the data and do filter on it, is n’t it?

I suggested reducing the amount of data by filtering for the updated field (which is supported by both Google’s API and the Google Calender node in n8n) first when fetching the calendar events.

Then perform the filtering on the created field afterwards.

What about using the Get All with the Updated Min option?

Lower bound for an event's last modification time (as a RFC3339 timestamp) to filter by. When specified, entries deleted since this time will always be included regardless of showDeleted. Optional. The default is not to filter by last modification time. 

This would assume that an events created time is also the last modified but at least you would have less results to process.

Another option would be to use the Google Calendar Trigger node and whenever a new result is created save it in a database somewhere then when you want to process them read the database process the events then clear the table ready for the next set.

2 Likes

Yeah, that’s what the example workflow does :slight_smile:

image

I do like the trigger suggestion though!

1 Like

What means of Updated min?
Is it useful if the user just created events, without any new update?!
if the last Updated_Event is for 2 months ago, it is not the right answer! because our user-created a new Event in the last 24 hours and he need to have it on the results list.

When creating a new event in Google Calendar, both fields created and updated get set. The updated field would thus always be equal to or later than the created field.

Or in other words, events updated in the last 24 hours should also include all events created in the last 24 hours.

1 Like

I am working on it :wink: Thanks!

1 Like