Synology Calendar API - Create events
This example creates all day events. It retrieves the public holidays of your country and create the events in the calendar. Please set the name of the calendar before trying.
Check the Synology API Collection for related examples.
[{"id":"74f23c2d7f46c6e6","type":"group","z":"55979001e6fb4b69","style":{"stroke":"#999999","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["b6b0c9f013faaada","237f0e28bc51d993","817fe4aa3109146d","e690e868037a1ec1","3e01c9157bcde375","a36ef4b433d974e6","19331fb107705f17","8a5eb8223353e0d3","f99b62cd13c0fd17"],"x":34,"y":39,"w":972,"h":162},{"id":"b6b0c9f013faaada","type":"http request","z":"55979001e6fb4b69","g":"74f23c2d7f46c6e6","name":"ipinfo.ip","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://ipinfo.io/json","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":300,"y":80,"wires":[["237f0e28bc51d993"]]},{"id":"237f0e28bc51d993","type":"function","z":"55979001e6fb4b69","g":"74f23c2d7f46c6e6","name":"date.nager.at","func":"const nextyear = (new Date()).getFullYear() + 1;\n\nnode.status({\n fill: \"green\",\n shape: \"ring\",\n text: `Request ${nextyear} for ${msg.payload.country}`\n}); \n\nmsg.method = \"GET\";\nmsg.url = `https://date.nager.at/api/v3/PublicHolidays/${nextyear}/${msg.payload.country}`;\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":500,"y":80,"wires":[["817fe4aa3109146d"]]},{"id":"817fe4aa3109146d","type":"http request","z":"55979001e6fb4b69","g":"74f23c2d7f46c6e6","name":"get holidays","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":710,"y":80,"wires":[["3e01c9157bcde375","8a5eb8223353e0d3"]]},{"id":"e690e868037a1ec1","type":"inject","z":"55979001e6fb4b69","g":"74f23c2d7f46c6e6","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":130,"y":80,"wires":[["b6b0c9f013faaada"]]},{"id":"3e01c9157bcde375","type":"function","z":"55979001e6fb4b69","g":"74f23c2d7f46c6e6","name":"create holidays","func":"var msgreq = {\n method: \"GET\",\n url: flow.get(\"synoentryurl\"),\n cookies: { id: flow.get(\"sid\") },\n headers: { 'X-SYNO-TOKEN': flow.get(\"synotoken\") }\n};\n\nnode.status({\n fill: \"green\",\n shape: \"ring\",\n text: `Process ${msg.payload.length} holidays`\n}); \n\n// SET THE NAME OF YOUR CALENDAR\nconst cal_id = flow.get(\"Feestdagen\");\n\nconst events = msg.payload.map(holiday => {\n const year = parseInt(holiday.date.substring(0, 4));\n const month = parseInt(holiday.date.substring(5, 7)) - 1; // JavaScript months are 0-based\n const day = parseInt(holiday.date.substring(8, 10));\n const startDate = new Date(Date.UTC(year, month, day));\n const endDate = new Date(Date.UTC(year, month, day + 1)); // Adding 1 day for dtend\n\n return {\n api: \"SYNO.Cal.Event\",\n method: \"create\",\n version: 5,\n cal_id: `\"${cal_id}\"`,\n original_cal_id: `\"${cal_id}\"`,\n summary: `\"${holiday.localName}\"`,\n is_all_day: true,\n tz_id: `\"\"`,\n dtstart: Math.floor(startDate.getTime() / 1000),\n dtend: Math.floor(endDate.getTime() / 1000),\n is_repeat_evt: false,\n color: `\"\"`,\n description: \"\",\n participant: \"[]\",\n notify_setting: \"[]\"\n };\n});\n\n// Send each event as a separate message\nevents.forEach(event => {\n const newMsg = { ...msgreq, payload: event };\n node.send(newMsg);\n});\n\n// Return null to indicate that no further processing is needed for the original message\nreturn null;\n\n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":500,"y":160,"wires":[["a36ef4b433d974e6"]]},{"id":"a36ef4b433d974e6","type":"http request","z":"55979001e6fb4b69","g":"74f23c2d7f46c6e6","name":"create event","method":"use","ret":"obj","paytoqs":"query","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":710,"y":160,"wires":[["19331fb107705f17"]]},{"id":"19331fb107705f17","type":"debug","z":"55979001e6fb4b69","g":"74f23c2d7f46c6e6","name":"response","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":900,"y":160,"wires":[]},{"id":"8a5eb8223353e0d3","type":"debug","z":"55979001e6fb4b69","g":"74f23c2d7f46c6e6","name":"holidays","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":900,"y":80,"wires":[]},{"id":"f99b62cd13c0fd17","type":"comment","z":"55979001e6fb4b69","g":"74f23c2d7f46c6e6","name":"Set name calendar in 'create holidays'","info":"","x":210,"y":160,"wires":[]}]