Get Calendar Events as JSON

Iā€™m trying to figure out a way to get my nextcloud calendar events returned in a json format. Iā€™ve read through the documentation, but Iā€™m not sure if Iā€™m looking in the right place. Iā€™m trying this:

https://user:pass@mynextcloud/ocs/v1.php/apps/calendar?format=json

But I canā€™t seem to get anywhere. Is there a service endpoint or other way to do this? Iā€™m looking into using JavaScript/Ajax to parse through my calendar.

Thanks in advance.

I donā€˜t know how to retrieve single events in json format. But you can get complete calendars in jcal format with (jcal = json for iCalendars):

https://NEXTCLOUD.URL/remote.php/dav/calendars/USERNAME/URI?export&accept=jcal

where URI for the desired calendar can be looked up in the database table oc_calendars (your table prefix might differ from oc_).
Of course you also need to authenticate with username and password in the request - I would not put the user credentials in the URL though.

Thatā€™s the WebDav url I believe. It appears to give me this message when attempting to access it via browser:

This is the WebDAV interface. It can only be accessed by WebDAV clients such as the Nextcloud desktop sync client.

Iā€™m able to curl forcing the method to be PROPFIND, but Iā€™m not seeing a list of events in json formatā€¦

Yes, this is the WebDAV-URL, but the export function works with a http client. Are you sure you appended the query-string for the get-request properly?
If I enter that link (including the query-string ?export&accept=jcal!) in a browser or request it via curl - I get a calender in json format. I know that at least the export function as an ics-file (without &accept=jcal) works since Nextcloud 9.0
Without the query-string I also get ā€žThis is the webdav interfaceā€¦ā€œ

I believe I got this working. I was looking at the principleuri field instead of uri in the databaseā€¦ The uri was called ā€œpersonalā€.

The json response is huge, is there any documentation on this export param or any other query parameters to reduce the size of the json response? I canā€™t seem to find any documentation on it.

You could add a start and end date.
I donā€˜t know of any documentation except the comments in the code:

IMHO there is actually a mistake: in line 20 it should probably be ?export (and not ?expand)
I hope that helps :slight_smile:

Thanks for this.

1 Like