LoginSignup
2

More than 3 years have passed since last update.

Python + RequestsでGaroon REST APIから組織に所属するユーザーの取得

Last updated at Posted at 2019-12-14

備忘録。
GaroonのRESTの機能、もう少し充実させてほしい。

参照

Garoon REST APIの共通仕様
https://developer.cybozu.io/hc/ja/articles/360000503306

組織の取得(GET)
https://developer.cybozu.io/hc/ja/articles/360017843172

ソース

import requests

url = 'https://(サブドメイン名).cybozu.com/g/api/v1/base/organizations/1/users'

headers = {
    'Host': '(サブドメイン名).cybozu.com:443', 
    # 'Content-Type': 'application/json',
     # 「ログイン名:パスワード」をBASE64エンコードしたものを値に指定。
     # xxxxxxxxxを書き換えること
    'X-Cybozu-Authorization': 'xxxxxxxxx',
    'Authorization': 'Basic xxxxxxxxx'
}

params = {
    'limit':1000
}

response = requests.get(url, headers=headers, params=params)

downloadData = response.json()

if len(downloadData) > 0:
    print(downloadData['users'])

出力結果

[{'id': '1', 'name': '山田 太郎', 'code': '0001'},
 {'id': '2', 'name': '山田 花子', 'code': '0002'}}]

補足

SOAPだと
「組織情報を取得する」で同様の情報の取得が可能
(ただしユーザー情報のうち、返却されるのはユーザーIDのみ)
https://developer.cybozu.io/hc/ja/articles/202511450

参考にした記事

Requests の使い方 (Python Library)
https://qiita.com/sqrtxx/items/49beaa3795925e7de666

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
2