How to switch enterprises via API
This page describes how switch enterprises via API. To switch enterprises means that an administrator can change from one tenant to another in order to work with another tenant. This is useful because you can only access some Abiquo entities and resources from within the enterprise that they belong to. For example, you must switch to an enterprise to deploy in its virtual datacenters or to edit its VM templates in the Apps library.
You will need the following resources:
More than one enterprise created in the platform
Your user role must include the following privileges.
ENTERPRISE_ENUMERATE
ENTERPRISE_ADMINISTER_ALL
Your user must have the new enterprise within your management scope.
In the Abiquo UI, you can switch enterprises in Home view or in Users view. For more details, see the following pages.
Summary diagram
The steps in this diagram link to the API reference guide resources and data entities sections.
Detailed steps
Get the user entity by name
To get an administrator from the enterprise they are currently working in, without knowing the enterprise ID, use a URL with a wildcard for all enterprises, which is the underscore character "_".
If you know the ID of the user, you can retrieve the user entity directly with the users link.
For example, the cloud admin user has an ID of 1, so the link would be: "https://example.com/api/admin/enterprises/_/users/1"Or use the "has" parameter to perform a search for the user by text such as username, name, or details
curl -X GET \ 'https://example.com/api/admin/enterprises/_/users?has=cloudadmin' \ -H 'Accept: application/vnd.abiquo.users+json;version=4.7' \ -u admin:xabiquo k --verbose | jq .
This request returns a collection of users. Keep the required user entity, which starts with the braces before its ID
{ "totalSize": 1, "links": [ { "rel": "first", "href": "https://example.com:443/api/admin/enterprises/_/users?limit=25&has=cloudadmin&by=name&asc=true" }, { "rel": "last", "href": "https://example.com:443/api/admin/enterprises/_/users?startwith=0&limit=25&has=cloudadmin&by=name&asc=true" } ], "collection": [ { "id": 10, "nick": "cloudadmin", "name": "Cloud", "surname": "Admin", "description": "Secondary cloud admin user", "email": "cloudadmin@example.com", "locale": "en_US", "authType": "ABIQUO", "active": true, "publicSshKey": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDgm0ckfblahblahblah", "allowedCIDRs": [], "firstLogin": false, "locked": false, "phoneNumber": "555123456", "links": [ { "title": "Marketing Department", "rel": "enterprise", "type": "application/vnd.abiquo.enterprise+json", "href": "https://example.com:443/api/admin/enterprises/3" }, { "title": "CLOUD_ADMIN", "rel": "role", "type": "application/vnd.abiquo.role+json", "href": "https://example.com:443/api/admin/roles/1" }, { "title": "cloudadmin", "rel": "edit", "type": "application/vnd.abiquo.user+json", "href": "https://example.com:443/api/admin/enterprises/3/users/10" }, { "title": "Global scope", "rel": "scope", "type": "application/vnd.abiquo.scope+json", "href": "https://example.com:443/api/admin/scopes/1" }, { "title": "virtual machines", "rel": "virtualmachines", "type": "application/vnd.abiquo.virtualmachines+json", "href": "https://example.com:443/api/admin/enterprises/3/users/10/action/virtualmachines" }, { "title": "pending tasks", "rel": "pendingtasks", "type": "application/vnd.abiquo.tasks+json", "href": "https://example.com:443/api/admin/enterprises/3/users/10/action/pendingtasks" }, { "title": "applications", "rel": "applications", "type": "application/vnd.abiquo.applications+json", "href": "https://example.com:443/api/admin/enterprises/3/users/10/applications" }, { "title": "async tasks", "rel": "asynctasks", "type": "application/vnd.abiquo.asynctasks+json", "href": "https://example.com:443/api/admin/enterprises/3/users/10/asynctasks" } ] } ] }
Get the new enterprise by name
curl -X GET \ 'https://example.com/api/admin/enterprises?has=Finance' \ -H 'Accept: application/vnd.abiquo.enterprises+json;version=4.7' \
Sample response
Find the required enterprise in the collection
Save the enterprise "edit" link
Edit the user entity to add the new enterprise link
Find the link with the "rel" value of "enterprise" and replace it with the new enterprise link. For example, to switch to enterprise 2, you could use the link below
Remember that the user entity must be complete in order to save the user, e.g. add an email attribute for the user because it is required.
Sample enterprise link
Sample user entity with new enterprise link
Update the user in any enterprise
In the user URL, replace the enterprise ID with a wildcard to represent all enterprises, which is the underscore character "_".
Perform a PUT request to the user, sending the updated user entity
cURL request
Sample response. Success status code: 200
Copyright © 2006-2024, Abiquo Holdings SL. All rights reserved