Batch user creation

Ported from Discord by @kahwatikid

So I’m just about to deploy Ayon to my students, is there a way I can batch load in a bunch of users? I saw there is a CSV publish option in the tray publisher…does that have anything useful in it with regards to users?

Answer by @BigRoy and @milan

For batchnig users rest api would be the easiest.

ayon_api can make that easy for you if you’re not familiar with rest requests, etc.

"""This is making a user jane."""

import ayon_api
payload = {
    "attrib": 
    {
        "fullName": "Jane Doe",
        "email": "jane.doe@ayon.cloud",
    },
    "active": True,
    "password": "string"

}
username = "jane"
result = ayon_api.put(f"users/{username}", **payload)
print(result.text)
"""And doing multiples. Potentially from there trivial to do it from e.g. a csv"""

import ayon_api
for username, fullname, email in [

    ("jane", "Jane Doe", "jane.doe@ayon.cloud"),
    ("john", "John Doe", "john@ayon.cloud"),
    ("steve", "Steve Doe", "steve@ayon.cloud"),
    ("notsteve", "Not Steve Doe", "liarliar@ayon.cloud"),
]:

    payload = {
        "attrib": 
        {
            "fullName": fullname,
            "email": email,
        },
        "active": True,
        "password": "string"
    
    }
    result = ayon_api.put(f"users/{username}", **payload)
    print(result, result.text)

TIP: Top right on the web frontend you can click the question mark to get to the REST API docs for your server version. Which may show you all the available options for the request.