LoginSignup
0
0

Python+REST APIでGaroonから会議室が含まれるデータを抽出する。

Last updated at Posted at 2023-12-13

Garoonの指定した会議室が含まれるデータを取得する

kintoneは要素の指定に自分で指定したIDを指定できるので、garoonもそうだろうと思っていたら数字でした。
そこが分かった記念にメモをあげておきます。
ただ、なんとなく、SOAPがかっこよさそうなので、SOAPで始めましたが、requestのデータ形式の定義がうまくいかずRESTにしました。

GetSchedule.py
import requests
import json

URL = 'https://(サブドメイン).cybozu.com/g/api/v1/schedule/events'

headers = {
     # 「ログイン名:パスワード」をBASE64エンコードした値をxxxxxxxxxに指定。
    'X-Cybozu-Authorization': 'xxxxxxxxx'
}

def main():
    res=GetSchedule(5) #IDは番号(garoonで指定したIDではない)
    jres=res.json() #json形式で取り出し
    print(jres)

def GetSchedule(f_id):
    params = {
        'target':f_id, #引数で指定した施設ID
        'targetType':'facility', #ターゲットを施設に指定
        'orderBy':'start desc', #スタート時間でソート
        'rangeStart':'2023-12-01T09:00:00+09:00', #会議開始時間(範囲)
        'rangeEnd':'2023-12-31T18:00:00+09:00' #会議終了時間(範囲)
    }

    response = None

    try :
        response = requests.get(URL, headers=headers, params=params)
        
    except Exception as e:
        print(e)
    
    return response

if __name__ == "__main__":
    main()

json形式に変換する前のRESPONSE番号

あと、さいしょprint(respose)をやってもResponse [200]やResponse [400]しか返ってこなくて意味が分からなかったけど、それぞれ下表のとおりです。

Num 意味
200 問い合わせ成功
400 ちょっと何言ってるかわからない

ただ、Response [400]のときは、responseをjsonに変換するとエラーメッセージを返してくれます。

参考資料

https://qiita.com/yamashi6/items/64955fe340bd90270c9d
https://qiita.com/yamashi6/items/3a6fe96a6a2efb8a52e1

https://cybozu.dev/ja/garoon/docs/rest-api/schedule/get-schedule-events/
https://cybozu.dev/ja/garoon/docs/overview/schedule-object/#schedule-object-propetry

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0