Confluence REST API to read Calendar events
Asked by Vaibhav Kamble:

I didn't find any official REST API to read calendar events but got to know about an unofficial end point to get event data in one of the discussion thread.

<https://stackoverflow.com/questions/44412554/calendar-info-using-confluence-api>

<https://community.atlassian.com/t5/Answers-Developer-Questions/Team-Calendar-list-events-API/qaq-p/532723>

End point - [https://yourconfluence.com/rest/calendar-services/1.0/calendar/events.json?subCalendarId=40xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\&userTimeZoneId=US%2FPacific\&start=2019-01-28T00%3A00%3A00Z\&end=2019-06-28T00%3A00%3A00Z](https://yourconfluence.com/rest/calendar-services/1.0/calendar/events.json?subCalendarId=40xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&userTimeZoneId=America%2FMexico_City&start=2018-11-28T00%3A00%3A00Z&end=2018-11-28T00%3A00%3A00Z)

Curl response I'm getting is {"success":true} but it doesn't have any event list. I did verified date ranges again and again and we have events within input date range.

So, is there something I'm doing wrong here? Any pointers? Thanks.


Answers:
author: Stephen Sifers
body: Hello Vaibhav and welcome to the Community!

The REST API endpoint you're using may be responding, but it doesn't seem to be fully developed as of now. There is a feature request for Confluence Server to have this added under support. You may find that feature request at [CONFSERVER-51323](https://jira.atlassian.com/browse/CONFSERVER-51323). We would suggest you vote and watch this request to receive future updates.

As of now, there is not an available REST API endpoint which will give you access to the calendar events.

Regards,  
Stephen Sifers

comments: author: Vaibhav Kamble
body: Thanks Stephen for your response. I will vote for feature request.


author: sarahc
body: Hey, just letting you (and anyone who stumbles across this post, like I did) know, the unofficial API is currently working.

I got the same problem as you, and eventually figured out that the cause was the structure of the calendar itself. It appears that Team Calendars stores each calendar as multiple sub-calendars, with each sub-calendar managing a different type of event (e.g. Leave, Travel, etc).

So it's returning success=true because technically that call is doing what it's supposed to: it's just there are no events associated with the derived calendar - which is likely to be the ID you're using - they're all in the sub-calendars.

The way I found to get it working was by using the ID's of the sub-calendars instead. The easiest way I found to figure those out is to go into the network calls. There you should find some number of calls (that correspond to the number of event types of events in that time range) that start like *events.json?subCalendarId=\<some numbers\>*. You can copy the URL's of those calls, and they'll give you the sub-calendar ID's and the different API calls you need to make.

Good luck!

comments: author: Mark Legg
body: I was having the same challenge and found rest/calendar-services/1.0/calendar/subcalendars.json? returns all the calenders I am subscribed to parents and all. I then went through the list to get the subcalender IDs and get the events for each sub calender.


author: Theo Dickinson
body: This snippet may help as I experienced the same issue.

Looking at the URL you posted the arguments seem to be missing this argument _ , which appears to be a timestamp/epoch. Once I added this value I received events and not just

```
{"success":true}?
```

Take a look at this Laravel/PHP code snippet that works for me

```

$response = Http::withToken(config('confluence.api.token'))
    ->get(sprintf('https://%s/rest/calendar-services/1.0/calendar/events.json',
        config('confluence.api.hostname')),
        [
            'subCalendarId' => config('confluence.calendar.sub_calendar_id'),
            'userTimeZoneId' => 'Australia/Sydney',
            'start' => $this->argument('start'),
            'end' => $this->argument('end'),
            '_' => now()->timestamp,
        ]);

```

The now()-\>timestamp is essentially the same as this bash command

```
date "+%s"
1614030878
```

Hope that helps

comments: author: Dan Bish
body: They must have not liked this hole. Even with the  
_  
param it returns  
{"success":true}

Any other ideas? I found the events and even the js files that parse the subcalendars . There is just way too much code there for me to bother with.

Has anyone figured out a good page scrape using regex or found another way to locate the list of sub-calendars (or how to request them)?

Thanks!


author: Dan Bish
body: Update:

Use headless chromium, deno or Node.js to grab the page with all of the dynamic parts and then parse out the information on the events. Then using that information you can pull the data without any problems.


author: Blaine Morgan
body: The Simple Solution (But not exactly REST) is to use the iCal export (the subscribe button). Then use an iCal library to parse the data.


Tags: calendar

developer

rest-api