Skip to content

API examples

Jon Clucas edited this page Jul 20, 2018 · 19 revisions

Login/Sign up User

login

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
)

sign up

password supplied

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

no password supplied

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

Assign user role from admin user, invite user

assign role

pull all groups and users in an API call

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"
    ])
)

pull specific groups and users in an API call

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"
    ])
)

invite user

girder_connection.post(
    "".join([
        "group/{}".format(role_id),
        "/invitation?userId={}".format(user_id),
        "&quiet=false&force=false"
    ])
)

CRUD volumes

create volumes

read volumes

update volumes

delete volumes

CRUD activities in volume

create activity

read activity

update activity

delete activity

CRUD screens in activity

create screen

read screen

update screen

delete screen

Clone this wiki locally