The calendar API is new in LINE WORKS v2.7. I would like to actually use it while introducing the changes.
Currently, there are two main calendar APIs.
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.
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.
--Create / delete calendar --Create / change / delete appointment
--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.
Using the new API, let's register a calendar and add an appointment. The following uses Python 3.8.0.
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.
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