2022年3月10日木曜日

Pythonを使用して、Nextcloudのグループを作成する

Pythonを使用して、Nextcloudのグループを作成するには、以下の手順を実行します

実行手順

1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="~/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2.lxmlとrequestsのインストール
以下のコマンドでlxml, requestsをインストールした仮想環境を作成します
mkdir -p ~/nextcloud_api

cd ~/nextcloud_api

poetry init -n

poetry add lxml

poetry add requests

poetry shell

3. プログラムの作成と実行
以下のPythonスクリプトを実行すると、グループを作成します。
nc_create_group.py
# coding: utf-8
from lxml import etree
import requests

user = 'adminuser'
password = 'adminpass'
host = 'yourhost:8080'

baseuri="http://" + user + ":" + password + "@" + host + "/ocs/v1.php/cloud/groups"
headers = {'content-type': 'application/x-www-form-urlencoded', 'OCS-APIRequest':'true'}
# 作成するグループIDを指定します
params  = {'groupid': 'テストグループ'}
response = requests.post(
  baseuri,
  params=params,
  headers=headers)
print(response.content)

・実行コマンド
python3 nc_create_group.py

関連情報

・User provisioning API
https://docs.nextcloud.com/server/latest/admin_manual/configuration_user/user_provisioning_api.html

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

0 件のコメント:

コメントを投稿