# Get events from google calendar

**URL:** <https://discourse.nodered.org/t/get-events-from-google-calendar/4830>\
**Category:** General\
**Created:** [13 November 2018 09:40 UTC](https://discourse.nodered.org/t/get-events-from-google-calendar/4830 "2018-11-13T09:40:49Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xenobiologist](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/xenobiologist/32/3737_2.png) [@Xenobiologist](https://discourse.nodered.org/u/Xenobiologist)\
**Post date:** [13 November 2018 09:40 UTC](https://discourse.nodered.org/t/get-events-from-google-calendar/4830/1 "2018-11-13T09:40:49Z")

</div>

Hello,

I would like to get a **list of events between two dates (start /end)** or **all events for the next (3 / 7) days**.  
I'm currently using _# node-red-node-google 0.1.4_

My problem is, that these nodes only provide the option to get the next event and nothing more.

Anybody who knows how to get achieve my goals?

Thanks!

So long,  
Mega

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [13 November 2018 16:47 UTC](https://discourse.nodered.org/t/get-events-from-google-calendar/4830/2 "2018-11-13T16:47:20Z")

</div>

The node currently doesn't do that.

You could write your own, or even better, add the functionality to the current node after speaking to it's author and benefit the entire community.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [13 November 2018 16:57 UTC](https://discourse.nodered.org/t/get-events-from-google-calendar/4830/3 "2018-11-13T16:57:48Z")

</div>

Indeed... we would welcome improvements to that node.

---

<div class="post-metadata">

**Author:** ![Xenobiologist](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/xenobiologist/32/3737_2.png) [@Xenobiologist](https://discourse.nodered.org/u/Xenobiologist)\
**Post date:** [14 November 2018 08:26 UTC](https://discourse.nodered.org/t/get-events-from-google-calendar/4830/4 "2018-11-14T08:26:27Z")

</div>

Sorry, I'm not a Javascript programmer. That is why I asked here to e.g. get a hint to use another node or something like that.  
I can try to write a python script 🙂 but that won't help the node.

Too sad, that there seems no other already working node for that task.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [14 November 2018 10:39 UTC](https://discourse.nodered.org/t/get-events-from-google-calendar/4830/5 "2018-11-14T10:39:19Z")

</div>

If you think you can write it in python then with a minimal bit of learning you should be able to do it in javascript. Especially when you are starting with a working node and just need to add features to it.

---

<div class="post-metadata">

**Author:** ![Marooned](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marooned/32/2858_2.png) [@Marooned](https://discourse.nodered.org/u/Marooned)\
**Post date:** [20 November 2018 12:16 UTC](https://discourse.nodered.org/t/get-events-from-google-calendar/4830/6 "2018-11-20T12:16:17Z")

</div>

`node-red-node-google` is [not working at all](https://discourse.nodered.org/t/using-google-calendar-node-authorisation-not-working/4745). However, there is `node-red-contrib-google` node which is wrapping Google API and is working like a charm. It's also much more flexible.

Put inject node and send

```auto
{
    "calendarId": "yourIdHere@gmail.com",
    "timeMin": "2018-11-19T09:11:13.562Z",
    "timeMax": "2018-11-21T09:11:13.562Z"
}

```

to `google` node. On `google` node set `API` to `calendar:v3` and `Operation` to `events.list` (of course you could leave that empty and provide everything by input node). `timeMin` and `timeMax` is what you want to create time window. Just checked it, works perfectly.

Of course, you need to configure `google` node but that is extremely simply (not like `node-red-node-google`):

- [generate JSON key](https://console.developers.google.com/apis/credentials/serviceaccountkey)
- [go to IAM & admin](https://console.cloud.google.com/)
- create `Project > editor` and copy created e-mail address of created service
- share your calendar with that e-mail

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [20 November 2018 12:32 UTC](https://discourse.nodered.org/t/get-events-from-google-calendar/4830/7 "2018-11-20T12:32:35Z")

</div>

Whist `node-red-node-google` was not working for you, there are others, that for what it was designed to do, it works perfectly well. It is incorrect to say it is not working at all.

But I'm happy you have managed to achieve what you want and thanks for sharing it.

---

<div class="post-metadata">

**Author:** ![Marooned](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marooned/32/2858_2.png) [@Marooned](https://discourse.nodered.org/u/Marooned)\
**Post date:** [20 November 2018 12:36 UTC](https://discourse.nodered.org/t/get-events-from-google-calendar/4830/8 "2018-11-20T12:36:57Z")

</div>

I've tested it on 3 completely different instances of NR on different machines and even architecture with different Google accounts. Every time the result was the same: success but no credentials were stored preventing that node from working - hence my comment.

Anyway, we can agree that the second node wrapping whole API fits the requirements and do the job.

---

<div class="post-metadata">

**Author:** ![Xenobiologist](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/xenobiologist/32/3737_2.png) [@Xenobiologist](https://discourse.nodered.org/u/Xenobiologist)\
**Post date:** [22 November 2018 12:09 UTC](https://discourse.nodered.org/t/get-events-from-google-calendar/4830/9 "2018-11-22T12:09:20Z")

</div>

Thanks, I installed the node. Copied the complete credentials.json file into the config node.  
After that I tried your example. The configuration seems ok, but as response in the debug tab, I only get "Error: Not found".

Any idea what I did wrong?

---

<div class="post-metadata">

**Author:** ![Marooned](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marooned/32/2858_2.png) [@Marooned](https://discourse.nodered.org/u/Marooned)\
**Post date:** [22 November 2018 12:25 UTC](https://discourse.nodered.org/t/get-events-from-google-calendar/4830/10 "2018-11-22T12:25:58Z")

</div>

Pick `CalendarList.list` as `Operation` and check if you have access to that particular calendar. If you see something in `payload.items` then copy `id` of that calendar and us it as `calendarId` for `events.list` call.

---

<div class="post-metadata">

**Author:** ![Xenobiologist](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/xenobiologist/32/3737_2.png) [@Xenobiologist](https://discourse.nodered.org/u/Xenobiologist)\
**Post date:** [22 November 2018 12:30 UTC](https://discourse.nodered.org/t/get-events-from-google-calendar/4830/11 "2018-11-22T12:30:13Z")

</div>

I got this:

> 22.11.2018, 13:28:00node: 5255c83.a57ca38  
> msg : Object  
> object  
> \_msgid: "3f48035.f465efc"  
> topic: ""  
> payload: object  
> kind: "calendar#calendarList"  
> etag: ""p3000""  
> nextSyncToken: "CAASG1lZ2FjYWwtMTU0MTc5NjUwMDQyMi5pYW0uZ3ZZDSDSDSD)(ZpY2VhY2NvdW50LmNvbQ=="  
> items: array[0]

---

<div class="post-metadata">

**Author:** ![Marooned](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marooned/32/2858_2.png) [@Marooned](https://discourse.nodered.org/u/Marooned)\
**Post date:** [22 November 2018 13:23 UTC](https://discourse.nodered.org/t/get-events-from-google-calendar/4830/12 "2018-11-22T13:23:00Z")

</div>

Ok, so `items` is empty, so you have no access to any calendar from this account.

1. If you go to [console](https://console.cloud.google.com/) and click `IAM & admin` on the left, do you see `service account` item in the table? (key icon, hover over to see type in string)
2. now if you go to your calendar settings, can you see the exact mail in `share` section?

---

<div class="post-metadata">

**Author:** ![Xenobiologist](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/xenobiologist/32/3737_2.png) [@Xenobiologist](https://discourse.nodered.org/u/Xenobiologist)\
**Post date:** [22 November 2018 13:40 UTC](https://discourse.nodered.org/t/get-events-from-google-calendar/4830/13 "2018-11-22T13:40:30Z")

</div>

Yes, it seems to work. Thank you. I didn't konw that I have to "open" the calendar for that generated email address. I thought all the keys and ids would be enough 🙂

---

<div class="post-metadata">

**Author:** ![Marooned](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marooned/32/2858_2.png) [@Marooned](https://discourse.nodered.org/u/Marooned)\
**Post date:** [22 November 2018 13:50 UTC](https://discourse.nodered.org/t/get-events-from-google-calendar/4830/14 "2018-11-22T13:50:06Z")

</div>

Well, you don't have to `"open" the calendar for that generated email`. You have to open any calendar you would like to view in NR and share it with that generated email 🙂 So that generated email (service account) is like a user for your API (NodeRed).

---

<div class="post-metadata">

**Author:** ![Xenobiologist](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/xenobiologist/32/3737_2.png) [@Xenobiologist](https://discourse.nodered.org/u/Xenobiologist)\
**Post date:** [22 November 2018 13:54 UTC](https://discourse.nodered.org/t/get-events-from-google-calendar/4830/15 "2018-11-22T13:54:17Z")

</div>

Yes, that's ok. You need a "user" to access the calender. But I thought giving the crendentials.json file to the configuration node would be enough.

---

<div class="post-metadata">

**Author:** ![Marooned](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marooned/32/2858_2.png) [@Marooned](https://discourse.nodered.org/u/Marooned)\
**Post date:** [22 November 2018 13:58 UTC](https://discourse.nodered.org/t/get-events-from-google-calendar/4830/16 "2018-11-22T13:58:26Z")

</div>

Yeah, that's the small issue with this node. It stores this JSON key in a way that it's being shared with the flow, so be careful with sharing your flow or pushing it to git.

---

<div class="post-metadata">

**Author:** ![uwaechte](https://avatars.discourse-cdn.com/v4/letter/u/77aa72/32.png) [@uwaechte](https://discourse.nodered.org/u/uwaechte)\
**Post date:** [9 February 2019 21:30 UTC](https://discourse.nodered.org/t/get-events-from-google-calendar/4830/17 "2019-02-09T21:30:19Z")

</div>

Hi,  
I am lost after generate JSON key.  
in IAM & admin I can see an related mail account fo rthe key.  
But how to use ?  
I tryed to put in the key in the JSON field of the connection node. But what about the Scopes field ?

best regards  
Uwe

---

<div class="post-metadata">

**Author:** ![tjl694](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tjl694/32/70227_2.png) [@tjl694](https://discourse.nodered.org/u/tjl694)\
**Post date:** [12 February 2019 13:53 UTC](https://discourse.nodered.org/t/get-events-from-google-calendar/4830/18 "2019-02-12T13:53:30Z")

</div>

@uwaechte using the email account you found in the 'IAM & Admin' section, go to your calendar's settings in Google Calendar and share the calendar with that email address.

Within the 'Scopes' field put the following:

> ```
> https://www.googleapis.com/auth/calendar
> https://www.googleapis.com/auth/calendar.events
> https://www.googleapis.com/auth/calendar.events.readonly
> https://www.googleapis.com/auth/calendar.readonly
> https://www.googleapis.com/auth/calendar.settings.readonly
> 
> ```

Having all of those might be overkill for your use but that is all the Scopes for the Calendar API

---

<div class="post-metadata">

**Author:** ![uwaechte](https://avatars.discourse-cdn.com/v4/letter/u/77aa72/32.png) [@uwaechte](https://discourse.nodered.org/u/uwaechte)\
**Post date:** [12 February 2019 19:29 UTC](https://discourse.nodered.org/t/get-events-from-google-calendar/4830/19 "2019-02-12T19:29:00Z")

</div>

many thank's that was the missing information

---

<div class="post-metadata">

**Author:** ![Asmegin](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@Asmegin](https://discourse.nodered.org/u/Asmegin)\
**Post date:** [18 February 2019 03:49 UTC](https://discourse.nodered.org/t/get-events-from-google-calendar/4830/20 "2019-02-18T03:49:38Z")

</div>

**EDIT: Figured it out! I used the following template with a timestamp inject and moment conversion. No idea if this is the best way to do what I need but it works...**

```auto
{
    "calendarId": "___",
    "maxResults": "1",
    "orderBy": "startTime",
    "timeMin": "{{payload}}",
    "singleEvents": "true"
}

```

Thanks for the help - this topic helped me set this up.

Just struggling with one thing - how do I return just the next occurring event? I have a recurring event and I need just the next instance returned, but it's giving me all events ever added to calendar. I've read through the Google Calendar API documents and have tried a bunch of stuff. I can get it to give me only one result but can't figure out the rest. For some reason it only lets you sort by date.

I tried using simpletime and passing myrawdate into a template of this:

```auto
{
    "calendarId": " _____",
    "maxResults": "1",
    "orderBy": "startTime",
    "timeMin": "{{myrawdate}}"
}

```

I get this as the payload:

```auto
payload: object
calendarId: " _____"
maxResults: "1"
orderBy: "startTime"
timeMin: "Sun Feb 17 2019 22:51:53 GMT-0500 (EST)"

```

But it obviously doesn't work. I know no programming, so I'm kind of just guesting here...I think it's changing the format of myrawdate but not sure why. Using moment, I can get the right time stamp but getting a different error.

"Error: The requested ordering is not available for the particular query."

[Next page](https://discourse.nodered.org/t/get-events-from-google-calendar/4830.md?page=2)
