This is an example of using simplecloud REST.

NOTE: This REST is in alpha version and some methods may not work correctly. If this happens, please open a ticket in the support section of your http://studio.simplecloud.io/ account.

NOTE: Currently the REST version works with username and password. This will be deprecated soon and API keys will be required instead. The section to generate API keys is currently not available on the platform. It will be available when the method is enabled in the REST.

The example is written in Python language, compatible with Python 2 and 3, but the simple REST can be consumed from any other language or system that allows requests.

The example shows at the beginning the use of the help function to obtain information about the methods available through REST.

Not all methods listed are functional. There are some methods for which a simple administrator role is required. The fact that they are listed is a side effect of the alpha state of REST. They will gradually disappear from the list returned by the help function, based on the permissions of the user or API key making the request. Other methods can only be used if you are the owner or manager of a studio.
For any questions or suggestions, as well as if you need assistance to perform any operation through the REST, you can open a ticket in the support section of your http://studio.simplecloud.io/ account. 



# encoding: utf-8

# Sample compatible with python 2 and python 3
# Requires pycurl library installed

import pycurl
import time
import json
import sys

try:
    # Python 2
    from StringIO import StringIO
except ImportError:
    # Python 3
    from io import BytesIO

from pprint import pprint


class SimpleAPIClient(object):
    def __init__(self, debug=False, verbose=False):
        self.VERBOSE = verbose
        self.DEBUG = debug
        self.SIMPLE_URL = "https://animation.simplecloud.io/api/rest/"

    def submit_data(self, request, cert=False):
        """
        Submits data and returns a dict with response
        Args:
            request(dict): dict with request
            cert(bool): To check if url is trusted or not using ssl.
                Default: False (do not check)
        Returns:
            dict: server response dict with keys:
                status: http status code
                message: server response message
                response: response of current request
        """
        # Configure Pycurl and add url
        c = pycurl.Curl()

        if not cert:
            c.setopt(pycurl.SSL_VERIFYHOST, 0)
            c.setopt(pycurl.SSL_VERIFYPEER, 0)

        c.setopt(pycurl.URL, self.SIMPLE_URL)
        c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json'])
        c.setopt(pycurl.POST, 1)

        # Add our request
        request = json.dumps(request, sort_keys=True, indent=4, separators=(',', ': '))
        if self.VERBOSE:
            print("Request: {}".format(request))
        c.setopt(pycurl.POSTFIELDS, request)

        # Add our string io object for pycurl to write response
        storage = StringIO() if sys.version_info[0] < 3 else BytesIO()
        c.setopt(pycurl.WRITEFUNCTION, storage.write)

        # Execute and close
        s = time.time()
        c.perform()
        if self.VERBOSE:
            print("Time: {}".format(time.time() - s))
        c.close()

        try:
            response = json.loads(storage.getvalue())
        except:
            # No json format, return raw data
            response = storage.getvalue()

        return response

    def help(self, method=None):
        """ To get info from the API call "help" request """

        # No method info means get info from ALL requests
        request = {
            "request": "help"
        }

        if method:
            # If you want info from a specific request
            request["method"] = method

        response = self.submit_data(request)

        # Some error
        if response["status"] != 200:
            return response

        # All OK

        if not method:
            return response["result"]
        else:
            response["result"][method] = '=====================================\nHELP RESULT - {}:\n\n{}\n=====================================\n\n'.format(method, response["result"][method])
            return response["result"][method]

    def start_session(self, user, password, mfa_code=None, mfa_type="totp"):
        """ Start session to get token """
        # DEPRECATED. There is no need for MFA in REST operations anymore
        # FUTURE DEPRECATION: In a near future, REST will only work using API key instead of user and password.

        request = {
            "request":'start_session',
            "username": user,
            "password": password
        }

        if mfa_code:
            request["mfa"] = {
                "code_verification": mfa_code,
                "algorithm": mfa_type
            }

        # Send data and get response
        response = self.submit_data(request)

        # Some error
        if response["status"] != 200:
            return response

        # All OK. Return token from response
        return response["result"]["ssid"]

    def request(self, request, **kwargs):
        if kwargs:
            kwargs["request"] = request
        else:
            kwargs = {"request": request}

        # Send data and get response
        response = self.submit_data(kwargs)

        if not response:
            return {"status": 403, "message": "forbidden operation"}

        # Some error
        if response["status"] != 200:
            return response

        # All OK. Return response
        return response["result"]


if __name__ == "__main__":
    client = SimpleAPIClient(verbose=False)

    # Get full list of available REST methods
    pprint(client.help())

    # Get help for certain methods
    print(client.help("list_machine_profiles"))
    print(client.help("list_softwares"))
    print(client.help("create_machine_profile"))
    print(client.help("delete_machine_profiles"))

    # ######################################################################
    # Sample to list all workstation profiles for a given studio, create a new one and then delete it.

    ssid = client.start_session("your_name", "your_password")

    kwargs = {
        "ssid": ssid,
        "studio": "your_studio_code",
        "type": ["os"]
    }

    # List operative systems
    response = client.request("list_softwares", **kwargs)
    pprint(response)

    # windows OS is software id 4. Can be obtained using request list_softwares with type "os"
    kwargs = {
        "ssid": ssid,
        "studio": "your_studio_code",
        "machine_profile": "TESTREST",
        "nicename": "Test in the Rest",
        "softwares": [4],
        "hardware_profiles": [1, 2],
        "internet": 1,
    }

    # Create new workstation profile in the studio, just with the operative system
    response = client.request("create_machine_profile", **kwargs)
    pprint(response)

    kwargs = {
        "ssid": ssid,
        "studio": "your_studio_code"
    }

    # List all studio workstation profiles
    response = client.request("list_machine_profiles", **kwargs)
    pprint(response)

    kwargs = {
        "ssid": ssid,
        "studio": "your_studio_code",
        "machine_profiles": ["TESTREST"],
        "kick": 0
    }

    # Delete the new workstation profile
    response = client.request("delete_machine_profiles", **kwargs)
    pprint(response)

    ######################################################################

Sample for help request output: 

'accept_terms' - 'Update last accepted terms of given worker'
'add_licenses' - 'Add a new license to given studio'
'admin_add_notification' - 'Add notification to db'
'admin_add_site' - 'Gets site details'
'admin_add_software' - 'Creates new software and software versions'
'admin_add_studio_members' - 'Add multiple new users to given studio'
'admin_change_client_password' - 'Change client passwords'
'admin_list_farms' - 'Lists farms'
'admin_list_notifications' - 'Returns a list of all notifications'
'admin_list_softwares' - 'Returns the list of available softwares for given parent_id and type. Both parameters are filters if not passed they wont be used in search.'
'admin_list_studio_workers' - 'Returns a list of users added to studio'
'admin_list_studios' - 'Returns a list of studios for given user session'
'admin_list_uris' - 'Returns a list of all notifications'
'admin_list_users' - 'Returns users'
'admin_list_vendors' - 'Returns a list of vendors for given user session'
'admin_studio_details' - 'Gets studio details'
'cancel_ibm_plan' - 'Cancel Client IBM Plan'
'close_ticket' - 'Close an existing ticket'
'connect_site_studio_status' - 'Checks if server has everything synched with given studio prior to connect in vdi.'
'contact_form' - 'Sends contact form to support by email'
'create_farm' - 'Creates a new studio farm'
'create_invoicing_data' - 'Creates a new invoicing data for given user'
'create_machine_profile' - 'Creates a new machine profile for given studio'
'create_mfa' - 'Create multi-factor authentication to given user'
'create_project' - 'Creates a new project for given user owner and studio'
'create_storage' - 'Creates a new storage for given studio'
'create_studio' - 'Creates a new studio for given sessions user'
'create_studio_group' - 'Creates a new ldap_group'
'create_studio_onboarding' - 'Creates a new studio for given sessions user and create storage onboarding'
'create_studio_sso' - 'Creates a new sso'
'create_ticket' - 'Create a new ticket'
'delete_farms' - 'Marks a list of farms to be deleted'
'delete_invoicing_data' - 'Delete invoicing data'
'delete_license_purchase' - 'Delete license purchase'
'delete_machine_profiles' - 'Deletes a list of machine profiles for given studio'
'delete_mfa' - 'Delete mfa for given algorythm type'
'delete_payment_method' - 'Delete users payment method'
'delete_project_workers' - 'Delete workers from a studios project'
'delete_storages' - 'Deletes a list of storages for given studio'
'delete_studio' - 'Marks a studio to be deleted'
'delete_studio_groups' - 'Delete groups for given studio'
'delete_studio_invitations' - 'Delete all given hash invitations for given studio'
'delete_studio_sso' - 'Delete a sso for sso id'
'delete_studio_workers' - 'Delete a list of workers from a studio'
'disable_farms' - 'Disable a list of farms for given studio'
'disable_machine_profiles' - 'Disables a list of machine profiles for given studio'
'disable_projects' - 'Disables a list of projects for given studio'
'disable_storages' - 'Disables a list of storages for given studio'
'disable_studio' - 'Disables a studio'
'disable_studio_groups' - 'Disable groups for given studio'
'disable_studio_sso' - 'Disable a sso for sso id'
'disable_studio_workers' - 'Disable workers in list for a group of workers on given studio'
'enable_farms' - 'Enable a list of farms for given studio'
'enable_machine_profiles' - 'Enable a list of machine profile for given studio'
'enable_projects' - 'Enables a list of projects for given studio status with enabled.'
'enable_storages' - 'Enables a list of storages for given studio'
'enable_studio' - 'Enables a studio'
'enable_studio_groups' - 'Enable groups for given studio'
'enable_studio_sso' - 'Enable a sso for sso id'
'enable_studio_workers' - 'Enable workers in list for a group of workers on given studio'
'end_session' - 'Ends session for given ssid'
'farm_details' - 'Creates a new farm for given studio'
'farm_projects' - 'Returns a list of projects linked to given farm'
'get_ibm_catalog' - 'Return IBM Catalog last version'
'get_project_workflow' - 'Return a list of workflow codename, nicename & date'
'get_project_workflow_details' - 'Return last workflow for given studio / project'
'get_sites' - ''
'get_statistics' - 'Get statistics by filter'
'get_usage_time' - 'Get used time for each studio'
'initialize_connect_site_studio' - 'Checks if server has everything synched with given studio prior to connect in vdi.'
'invite_details' - 'Return invitation details for given user / studio'
'invite_registered' - 'Invites a registered user'
'invite_unregistered' - 'Invites a user to be registered in system'
'invoice_details' - 'Return invoice details'
'invoicing_data_details' - 'Returns invoicing data details'
'kb_articles' - 'Return all knowledge base articles from a given language'
'kb_content' - 'Return all knowledge base content from a given language'
'license_details' - 'Return license details'
'license_purchase' - 'Purchase licenses'
'license_purchase_details' - 'License purchase details'
'list_available_nodes' - 'Creates a new farm on database'
'list_domain_net_bios' - 'Returns a list of domain by owner or studio'
'list_farms' - 'Lists farms for given studio'
'list_hardware_profiles' - 'Lists all hardware profiles on database'
'list_invoices' - 'List invoices'
'list_invoicing_data' - 'List of payment profiles for specific user'
'list_licenses' - 'List licenses'
'list_machine_profiles' - 'Returns a list of machine profiles for given studio keys.'
'list_mount_points' - 'Returns a list of mount points for given project'
'list_notifications' - 'Returns a list of notifications'
'list_payment_methods' - 'List of payment methods for specific user'
'list_plan_templates' - 'Return list of plan templates'
'list_project_farms' - 'Update a storage for given studio'
'list_project_workers' - 'Returns users from given project'
'list_projects' - 'Returns a list of projects for given owner'
'list_softwares' - 'Returns the list of available softwares for given parent_id and type. Both parameters are filters if not passed they wont be used in search.'
'list_sso' - 'Returns a list of sso'
'list_storages' - 'Returns a list of storages for given studio keys.'
'list_studio_groups' - 'Returns a list of all groups for given studio'
'list_studio_invitations' - 'Returns all invitations for given studio and owner'
'list_studio_machine_profiles' - 'Returns a list of machine profiles for given studio keys.'
'list_studio_projects' - 'Returns a list of projects associated to a studio'
'list_studio_sso_users' - 'Returns workers info.'
'list_studio_workers' - 'Returns a list of users added to studio'
'list_studios' - 'Returns a list of studios for given user session'
'list_tickets' - 'Returns a list of tickets'
'list_tickets_categories' - 'List tickets categories'
'list_trust_domain' - 'Returns a list of domain user has'
'list_users' - 'Returns users'
'list_vdi_sessions' - 'Return VDI Sessions with Horizon Sessions for all studios that user is owner or manager'
'list_vendors' - 'List vendors'
'list_worker_ftp_permissions' - 'Return users ftp permissions to machines'
'list_workflow_templates' - 'Gets pre-made workflows list with codename and nicename'
'machine_profile_details' - 'Returns machine profile details for connect'
'operation_checkers' - 'Launch check method'
'payment_method_details' - 'List of payment profiles for specific user'
'ping' - 'Returns 200 OK '
'pipe_delete_entity' - 'Return all tasks in project db'
'pipe_delete_publish' - 'Return all tasks in project db'
'pipe_delete_task' - 'Return all tasks in project db'
'pipe_insert_entity' - 'Return all tasks in project db'
'pipe_insert_task' - 'Return all tasks in project db'
'pipe_list_disciplines' - 'Return all disciplines in project db'
'pipe_list_entities' - 'Return all entities in project db'
'pipe_list_entity_status_types' - 'Return all entity status types in project db'
'pipe_list_entity_type_headers' - 'Return all tasks in project db'
'pipe_list_entity_types' - 'Return all entity types in project db'
'pipe_list_publish' - 'Return all publishes in project db'
'pipe_list_publish_headers' - 'Return all publishes in project db'
'pipe_list_publish_status_types' - 'Return all publish status types in project db'
'pipe_list_task_status_types' - 'Return all task status types in project db'
'pipe_list_tasks' - 'Return all tasks in project db'
'pipe_list_tasks_headers' - 'Return all tasks in project db'
'pipe_update_entity' - 'Return all tasks in project db'
'pipe_update_publish' - 'Return all tasks in project db'
'pipe_update_task' - 'Return all tasks in project db'
'plan_details' - 'Return details of given plan'
'plan_overview' - 'Return minimum client plan info'
'plan_purchase' - 'Performs a plan purchase'
'plan_template_details' - 'Return details of given plan template'
'plan_upgrade' - 'Performs a upgrade plan'
'project_details' - 'Returns a list of projects associated to a studio'
'project_summary' - 'Return project nicename, codename & thumbnail'
'project_worker_details' - 'Returns workers info.'
'purchase_ibm_plan' - 'Setup Client Plan with IBM Plan Template'
'purge_projects' - 'Deletes a list of projects for given studio - adds to_delete:date status'
'purge_storages' - 'Deletes a list of storages for given studio - adds to_delete:date status'
'recover_projects' - 'Removes to_delete:date from a list of projects from given studio'
'recover_storages' - 'Recovers a list of storages for given studio - removes to_delete:date status'
'recover_studio' - 'Removes to_delete status from a studio to recover it'
'register_user' - 'Registers a new user\n'
'remove_users_sessions' - 'Remove users sessions'
'resend_activate_email' - 'Resend email for activate given user'
'reset_password' - 'Reset user password and send it to user.'
'restore_session' - 'Restores user session using a passphrase'
'revoke_invitations' - 'Revokes an invitation by its hash'
'session_info' - 'Returns users session info.'
'set_project_workflow' - 'Adds workflow to database and saves it inside.'
'skip_onboarding' - 'Remove onboarding worker status'
'start_session' - 'Start session for given user.'
'storage_details' - 'Returns a list of storages for given studio keys.'
'storage_projects' - 'Returns a list of projects linked to given storage'
'studio_auto_invite' - 'Invite users to studio without sending email'
'studio_connect_details' - 'Return users connect permissions details in given studio'
'studio_details' - 'Gets studio details'
'studio_group_details' - 'Returns details for given group'
'studio_leave' - 'Delete worker from a studio'
'studio_license_servers' - 'Return details of given plan'
'studio_overview' - 'Return studio overview'
'studio_worker_details' - 'Returns workers info.'
'studio_worker_role' - 'Returns workers role in given studio'
'test_timeout' - 'Force a timeout by time.sleep()'
'test_vdi_connect' - 'Creates a VDI session and return it if worker can connect to given workstation'
'ticket_details' - 'Create a new ticket'
'update_farm' - 'Updates a farm on database'
'update_farm_projects' - 'Update a storage for given studio'
'update_invoicing_data' - 'Updates invoicing data.'
'update_machine_profile' - 'Updates a machine profile for given studio'
'update_password' - 'Updates user password'
'update_project' - 'Creates a new project for given user owner and studio'
'update_project_workers' - 'Updates project worker permissions on database'
'update_project_workflow' - 'Update workflow to database and saves it inside.'
'update_storage' - 'Update a storage for given studio'
'update_storage_async' - 'Update storage by powershell'
'update_studio' - 'Inserts a studio on database'
'update_studio_groups' - 'Update a ldap_group'
'update_studio_sso' - 'Update a sso for id'
'update_studio_timezone' - 'Update studio timezone'
'update_studio_workers' - 'Updates internet access, ftp upload and ftp download permissions for a group of workers on given studio'
'update_ticket' - 'Create a new ticket'
'update_user' - 'Updates summus user info'
'update_web_preferences' - 'Update Web Config Data for given user'
'update_worker_site' - 'Updates an user site preferences on its simple worker profile'
'update_worker_timezone' - 'Updates an user timezone preferences on its simple worker profile'
'uri_details' - 'Gets uri details'
'user_in_other_machine' - 'Return tru if user has active session in other machine'
'user_profile_details' - 'Returns users profile details.'
'validate' - 'Operation to call specific operation to validate uuid'
'validate_connection_sso' - 'Return info about validation like request(operation), origin, ssid_required'
'validate_details' - 'Return info about validation like request(operation), origin, ssid_required'
'validate_farm_codename' - 'Lists farms for given studio'
'validate_machine_profile_codename' - 'Validates machine profile codename'
'validate_mfa' - 'Validate multi-factor authentication to given user'
'validate_password' - 'Validates user password'
'validate_project_codename' - 'Validates project codename'
'validate_storage_codename' - 'Validates storage codename'
'validate_studio_codename' - 'Validates studio codename'
'validate_studio_group_codename' - 'Validates studio group codename'
'vdi_connect' - 'Creates a VDI session and return it if worker can connect to given workstation'
'vdi_details' - 'Check vdi permissions for given worker (session[username]), studio, machine_profile'
'workflow_template_details' - 'Gets workflow dict for given codename'