Initialisation :

Cette partie de code doit être au début de votre programme.

import json
import requests

domain = "cloud.leviia.com"; # Your pro domain
auth=('antoine', 'password'); # admin user
headers = {"OCS-APIRequest": "true"}


Remplacez « domain », « antoine » et « password » par votre nom de domaine, votre identifiant et votre mot de passe.

Créer un utilisateur :

userinfo = {
  "userid":userid, # Must be unique !
  "password":"", # If empty an email will be send
  "displayName":name, # Anything doesn't have to be unique
  "email":email, # If email is set and password is empty an email will be send to user to ask for first password
  "groups":[group-name], # Any group you wish or empty. List of strings
  "subadmin":[], # As you need
  "quota":size, # The quota for this user
  "language":lang # Lowercase ISO standard
}

# Exemple for a user: "thomas.dupond" with 
# username: "thomas", email: "thomas.dupond@mail.com", in the group: "test", with 1 To of quota and french.

# userinfo = {
#   "userid":"thomas.dupond",
#   "password":"",
#   "displayName":"thomas",
#   "email":"thomas.dupond@mail.com",
#   "groups":["test"],
#   "subadmin":[],
#   "quota":"1 TB",
#   "language":"fr"
# }

req = requests.post("https://"+domain+"/ocs/v2.php/cloud/users", json = userinfo, headers=headers, auth=(auth[0], auth[1]))

Modifier un utilisateur :

userinfo = {
  "password":"", # If empty an email will be send
  "displayName":name, # Anything doesn't have to be unique
  "email":email, # If email is set and password is empty an email will be send to user to ask for first password
  "groups":[group-name], # Any group you wish or empty. List of strings
  "subadmin":[], # As you need
  "quota":size, # The quota for this user
  "language":lang # Lowercase ISO standard
}

req = requests.put("https://"+domain+"/ocs/v2.php/cloud/users/"+userid, json = userinfo, headers=headers, auth=(auth[0], auth[1]))

Remplacez « userid » par l'id de l'utilisateur que vous souhaitez modifier.

Récupérer les informations d'un utilisateur :

req = requests.get("https://"+domain+"/ocs/v2.php/cloud/users/"+userid, headers=headers, auth=(auth[0], auth[1]))


Supprimer un utilisateur :

req = requests.delete("https://"+domain+"/ocs/v2.php/cloud/users/"+userid, headers=headers, auth=(auth[0], auth[1]))

Remplacez « userid » par l'id de l'utilisateur que vous souhaitez supprimer.
Cet article a-t-il répondu à vos questions ?
Annuler
Merci !