Skip to content

Organization

This section shows how to create, modify and list organizations in AI & Analytics Engine using API access through SDK

Retrieving information of an organization

You can retrieve information of an organization that has been created by specifying the org id.

from aiaengine import Org

org = Org(id='b6240512-cd17-43a0-8297-84c51c1bc5a0') # replace with your org id
print(f'name = {org.name}, description = {org.description}')
package com.aiaengine.examples.org;

import com.aiaengine.Engine;
import com.aiaengine.Org;

import java.io.FileNotFoundException;

public class GetOrgApp {
    public static void main(String[] args) throws FileNotFoundException {
        Engine engine = new Engine();
        //replace with your org id
        String orgId = "b6240512-cd17-43a0-8297-84c51c1bc5a0";
        Org org = engine.getOrg(orgId);
        System.out.println(String.format("Name=%s, description=%s", org.getName(), org.getDescription()));
    }
}

Updating information for an organization

You can also update the name and description for an exisiting organization.

from aiaengine import Org

org_id = 'b6240512-cd17-43a0-8297-84c51c1bc5a0' # replace with your org
org = Org(id=org_id)
org.update(name='Updated Org', description='This org has been updated')
package com.aiaengine.examples.org;

import com.aiaengine.Engine;
import com.aiaengine.Org;
import com.aiaengine.org.request.UpdateOrgRequest;

import java.io.FileNotFoundException;

public class UpdateOrgApp {
    public static void main(String[] args) throws FileNotFoundException {
        Engine engine = new Engine();
        //replace with your org id
        String orgId = "b6240512-cd17-43a0-8297-84c51c1bc5a0";
        Org org = engine.getOrg(orgId);
        org.update(UpdateOrgRequest.builder().name("Updated Org").description("This org has been updated").build());
    }
}

Listing organizations for a user

For the current authenticated user, you can list all the organizations that this user are associated with.

from aiaengine import Org

org_id = 'b6240512-cd17-43a0-8297-84c51c1bc5a0' # replace with your org id
org = Org(id=org_id)
user_orgs = Org.list_user_orgs()
print(user_orgs)
package com.aiaengine.examples.org;

import com.aiaengine.Engine;
import com.aiaengine.Org;

import java.io.FileNotFoundException;
import java.util.List;

public class ListUserOrgsApp {
    public static void main(String[] args) throws FileNotFoundException {
        Engine engine = new Engine();
        List<Org> orgs = engine.listUserOrgs();
        orgs.forEach(org -> System.out.println(org.getName()));
    }
}

Manage users of the organization

Listing users that can access an organization

You can list all the users who can access to an organization by proving the org id.

from aiaengine import Org

org_id = 'b6240512-cd17-43a0-8297-84c51c1bc5a0' # replace with your org id
org = Org(id=org_id)
org_users = org.list_users()
for org_user in org_users:
    print(org_user)
package com.aiaengine.examples.org;

import com.aiaengine.Engine;
import com.aiaengine.Org;
import com.aiaengine.org.OrgUser;

import java.io.FileNotFoundException;
import java.util.List;

public class ListOrgUsersApp {
    public static void main(String[] args) throws FileNotFoundException {
        Engine engine = new Engine();
        Org org = engine.getOrg("cae24b10-e6b0-4d61-8cef-a9f4b8f6133d");
        List<OrgUser> orgUsers = org.listUsers();
        orgUsers.forEach(orgUser -> System.out.println(orgUser.getUser().getName()));
    }
}

Adding a user to an organization

By specifying the email and role of an existing user in the platform, you can add the user into your organization.

from aiaengine import Org, UserRoles

# get the org
org = Org(id='b6240512-cd17-43a0-8297-84c51c1bc5a0') # replace with your org id

# add the user using the email
org.add_user(user_email='user@example.com', role=UserRoles.OrgViewer)
package com.aiaengine.examples.org;

import com.aiaengine.Engine;
import com.aiaengine.Org;
import com.aiaengine.user.UserRoles;

import java.io.FileNotFoundException;

public class AddOrgUserApp {
    public static void main(String[] args) throws FileNotFoundException {
        Engine engine = new Engine();
        Org org = engine.getOrg("cae24b10-e6b0-4d61-8cef-a9f4b8f6133d");
        org.addUser("user@example.com", UserRoles.OrgViewer);
    }
}

Removing a user from an organization

By specifying the emailof an existing user in the platform, you can remove the user from your organization.

from aiaengine import Org

# get the org by its ID
org = Org(id='b6240512-cd17-43a0-8297-84c51c1bc5a0') # replace with your org id

# remove the user from the org using user email
org.remove_user(user_email='user@example.com')
package com.aiaengine.examples.org;

import com.aiaengine.Engine;
import com.aiaengine.Org;

import java.io.FileNotFoundException;

public class RemoveOrgUserApp {
    public static void main(String[] args) throws FileNotFoundException {
        Engine engine = new Engine();
        Org org = engine.getOrg("cae24b10-e6b0-4d61-8cef-a9f4b8f6133d");
        org.removeUser("user@example.com");
    }
}

Deleting an organization

If an organization (with no active subscription) is no longer needed, you can remove it.

from aiaengine import Org

org_id = 'b6240512-cd17-43a0-8297-84c51c1bc5a0' # replace with your org id
org = Org(id=org_id)
org.delete()
package com.aiaengine.examples.org;

import com.aiaengine.Engine;
import com.aiaengine.Org;
import com.aiaengine.org.request.UpdateOrgRequest;

import java.io.FileNotFoundException;

public class DeleteOrgApp {
    public static void main(String[] args) throws FileNotFoundException {
        Engine engine = new Engine();
        //replace with your org id
        String orgId = "b6240512-cd17-43a0-8297-84c51c1bc5a0";
        Org org = engine.getOrg(orgId);
        org.delete();
    }
}