23 June 2024

Synology Calendar API v5

By Bolukan

Synology has not yet published any documentation about the Calendar API v5. There is also little information available on forums. I have found that the network traffic of the Synology Calendar App gives me the information to use the API myself. In this article I explain how to fill your calendar from Node-red using version 5 of the API.

An important change is the format of certain data in the request. Text fields must be surrounded by double-quotes in the request. So
summary: summary,
has to become
summary: `"${summary}"`,

Time fields are changed from text to unix timestamps numbers. So
dtstart: "2025-01-01T00:00:00",
has to become
dtstart: 1735689600,
and in a response the API also sends a string, in this example a date for an all day event:
dtstart_string: "20250101"

And empty strings and empty arrays have to be send as ‘””‘, respectively ‘[]’:

   color: `""`,   participant: "[]",

To add an event you’ll need the following steps:
Authenticate and get the token/security identifier:

https://mysynology/webapi/auth.cgi?api=SYNO.API.Auth&version=7&method=login&account=myaccount&passwd=mypassword&session=mysessionname&format=sid&enable_syno_token=yes
flow.set("sid", msg.payload.data.sid);
flow.set("synotoken", msg.payload.data.synotoken);
flow.set("device_id", msg.payload.data.device_id);

Retrieve a list of calendars, use:

msg.payload  = {
  api: "SYNO.Cal.Cal",
  version: 5,
  method: "list",
  cal_type: `"event"`
};

Create an all day event with dtstart as date object, to return a timestamp like 1735689600:

var event = {
   api: "SYNO.Cal.Event",
   method: "create",
   version: 5,
   cal_id: `"${cal_id}"`,
   original_cal_id: `"${cal_id}"`,
   summary: `"${summary}"`,
   is_all_day: true,
   tz_id: `""`,
   dtstart: Math.floor(dtstart.getTime()/1000),
   dtend: Math.floor(dtend.getTime()/1000),
   is_repeat_evt: false,
   color: `""`,
   description: `""`,
   participant: "[]",
   notify_setting: "[]",
};