-
-
Notifications
You must be signed in to change notification settings - Fork 4
API examples
Jon Clucas edited this page Jul 20, 2018
·
19 revisions
- Login/Sign up User
- Assign user role from admin user, invite user
- CRUD volumes
- CRUD activities in volume
- CRUD screens in activity
import girder_client as gc
girder_connection = gc.GirderClient(
apiUrl='http://mindlogger-girder-atlas.a4vwd5q7ib.us-east-1.elasticbeanstalk.com/api/v1'
)
girder_connection.authenticate(
user=username,
password=password,
apiKey=apiKey
)
girder_connection.post(
"&".join([
"user?login={}".format(username),
"email={}".format(email),
"firstName={}".format(firstname),
"lastName={}".format(lastname),
"password='{}'".format(password),
"admin=false"
])
) # create new user
import random
import string
girder_connection.post(
"&".join([
"user?login={}".format(username),
"email={}".format(email),
"firstName={}".format(firstname),
"lastName={}".format(lastname),
"password='{}'".format(
"".join(
random.sample(
string.printable,
28
)
)
), # random password
"admin=false"
])
) # create new user
girder_connection.put(
"user/password/temporary?email={}".format(
email
)
) # send temporary password
role = "Viewers"
groups = girder_connection.get(
"group"
) # get all groups
role_id = [
group for group in groups if group['name']==role
][0]["_id"] # get Girder_id for "Viewers" group
users = girder_connection.get("user")
user_id = [
user for user in users if user['email']==email
][0]["_id"] # get Girder_id for user
girder_connection.post(
"".join([
"group/{}".format(role_id),
"/invitation?userId={}".format(user_id),
"&quiet=true&force=true"
])
)
role = "Viewers"
role_id = girder_connection.get(
"group?text={}".format(role)
)[0]["_id"]
user_id = girder_connection.get(
"user?email={}".format(email)
)[0]["_id"]
girder_connection.post(
"".join([
"group/{}".format(role_id),
"/invitation?userId={}".format(user_id),
"&quiet=true&force=true"
])
)
girder_connection.post(
"".join([
"group/{}".format(role_id),
"/invitation?userId={}".format(user_id),
"&quiet=false&force=false"
])
)