[PYTHON] Throw appointments to others with the LINE WORKS calendar API

The calendar API is new in LINE WORKS v2.7. I would like to actually use it while introducing the changes.

Calendar API type

Currently, there are two main calendar APIs.

Previous (~ v2.6) calendar API

There are two main types of LINE WORKS APIs: server APIs and service APIs.

API type Feature
Server API API that works with system privileges, no user login required
Service API API that works with each user's authority, user login is required in Web UI when using

Until now, the calendar API was provided only as a service API. Therefore, it was only possible to operate your own calendar with your own authority.

From now on (v2.7 ~) calendar API

Along with the v2.7 update, a new server API has been added that can be used for data copying during migration. However, at this time, the functions provided are limited.

Features provided by the calendar server API

--Create / delete calendar --Create / change / delete appointment

Key features not provided by the calendar server API

--Inquiry / correction of calendar information --Calendar list query --Inquiry of the schedule list in the calendar --Inquiry of schedule details

In this way, you can use "create a new calendar and throw it in", but "reference existing information" will continue to be limited to the service API.

Try using the calendar API

Using the new API, let's register a calendar and add an appointment. The following uses Python 3.8.0.

Creating a calendar

Click here for the API description. Creating a calendar

calendarlist.py



import json
import requests
import urllib.parse

APIID="API ID obtained from the Developer Console"
SERVER_CKEY = "Server Consumer Key obtained from Developer Console"
SERVER_TOKEN = "Server authentication token"

def CalendarlistS(ServerTOKEN,AccountId,**CalParams):
    #Creating a request URL
    apiurl =  'https://apis.worksmobile.com/r/'+ APIID + 'calendarList/'+ urllib.parse.quote(AccountId) + '/calendarList'
    
    header = {
        'consumerKey': SERVER_CKEY,
        'Authorization': 'Bearer ' + SERVER_TOKEN,
        'Content-Type': 'application/json'
    }
    #Pass CalParams as a calendar setting
    r = requests.post(apiurl, headers = header, json = CalParams)
    return r

#Creation example
cal=CalendarlistS(SERVER_TOKEN,'demo@exampletenant',name='demo calendar',description='hogehoge')

#The created calendar ID goes into returnValue
Cal_ID = cal.json()['returnValue']

Note that many other APIs use the value externalKey to specify members, but the calendar API accountId is in ID @ domain format.

Add appointments to your calendar

Next, register the appointment in the created calendar.

calendarlist.py


def CalendareventS(ServerTOKEN,AccountId,CalendarId,**EventParams):
    #Creating a request URL
    apiurl =  'https://apis.worksmobile.com/r/'+ APIID + '/calendar/v1/' + urllib.parse.quote(AccountId) + '/calendars/'+CalendarId+'/events'
    
    header = {
        'consumerKey': SERVER_CKEY,
        'Authorization': 'Bearer ' + ServerTOKEN,
        'Content-Type': 'application/json'
    }
    #Pass EventParams as appointment information
    r = requests.post(apiurl, headers = header, json = EventParams)
        return r

Appointment parameters are specified in ical format. Refer to here for how to write.

demo.ics


BEGIN:VCALENDAR
VERSION:2.0
PRODID:NO Calendar
CALSCALE:GREGORIAN
BEGIN:VTIMEZONE
TZID:Asia/Tokyo
BEGIN:STANDARD
DTSTART:19700101T000000
TZNAME:GMT+09:00
TZOFFSETFROM:+0900
TZOFFSETTO:+0900
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
SEQUENCE:0
CLASS:PUBLIC
TRANSP:OPAQUE
UID:demodemodemo-001-001
DTSTART;TZID=Asia/Tokyo:20191212T150000
DTEND;TZID=Asia/Tokyo:20191212T160000
SUMMARY:Sample schedule
DESCRIPTION:Detailed explanation
LOCATION:Tokyo office
ORGANIZER;CN=Yamada Taro:mailto:[email protected]
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;CN=Attendees:mailto:[email protected]
CREATED:20191212T015408Z
LAST-MODIFIED:20191212T015408Z
DTSTAMP:20191212T015409Z
END:VEVENT
END:VCALENDAR

You must register the appointments one by one. I think the ics file exported from the calendar app contains multiple appointments (VEVENTs), but be aware that if you try to import it as it is, an error will occur. This is how you register your appointments in the calendar you created first.

python


f=open('demo.ics')
eventdata=f.read()
f.close()
event=CalendareventS(SERVER_TOKEN,'demo@exampletenant',Cal_ID,ical=eventdata)

There is a problem that it can not be registered in the personal basic calendar and it is only in one direction because there is no reference, but it seems that it can be conveniently used for pouring schedules from other systems.

Recommended Posts

Throw appointments to others with the LINE WORKS calendar API
I created a Python library to call the LINE WORKS API
Get holidays with the Google Calendar API
I tried to notify the train delay information with LINE Notify
The first API to make with python Djnago REST framework
A script that makes it easy to create rich menus with the LINE Messaging API
Call the API with python3.
I want to know the weather with LINE bot feat.Heroku + Python
Create an alias for Route53 to CloudFront with the AWS API
[September 2020 version] Explains the procedure to use Gmail API with Python
How to send a request to the DMM (FANZA) API with python
Create a REST API to operate dynamodb with the Django REST Framework
Specifying the date with the Twitter API
Hit the Etherpad-lite API with Python
How to make an artificial intelligence LINE bot with Flask + LINE Messaging API
I tried to make "Sakurai-san" a LINE BOT with API Gateway + Lambda
I tried to get the authentication code of Qiita API with Python.
I tried to get the movie information of TMDb API with Python
Access the Docker Remote API with Requests
Send data to DRF API with Vue.js
I tried to touch the COTOHA API
Match the colorbar to the figure with matplotlib
Play with puns using the COTOHA API
The road to compiling to Python 3 with Thrift
[LINE Messaging API] I want to send a message from the program to everyone's LINE
Let's create it by applying Protocol Buffer to the API with Serverless Framework.
Create an app that works well with people's reports using the COTOHA API
[Free] Hit the Clash Royale API from lambda and send it to LINE
The front engineer tried to automatically start go's API server with systemd quickly
To automatically send an email with an attachment using the Gmail API in Python
I tried to automatically send the literature of the new coronavirus to LINE with Python