Switch Enterprises via API

In Abiquo the cloud admin user can change from one tenant to another in order to work with another tenant. This is useful because some Abiquo entities, such as virtual datacenters, can only be accessed from within the enterprise they belong to. This functionality is only available to the cloud administrator and other users the privileges to "List all enterprises within scope" and "Allow user to switch enterprise". Users must have the new enterprise within their management scope.

 In the UI, you can switch enterprises by clicking the switch enterprises button beside the enterprise name in the Home view or Users view enterprise list. In the API, you should perform the following steps.

  1. Retrieve the user entity
    • You will need the ID of the user in the API. To get a cloud admin user from whichever enterprise they are currently in, run the get request with a wildcard for all enterprises represented by the underscore character "_". 
      For example, for the cloud admin user with a user ID of 1.

      curl -X GET "https://example.com/api/admin/enterprises/_/users/1" \
      	 -H "Accept: application/vnd.abiquo.user+json;version=4.6"

      Remember that you can use the "has" parameter to perform a search for the user by text such as username, name, or details

  2. Edit the user entity and remove the existing enterprise link and replace it with a new one, for the new enterprise ID, for example to switch to enterprise 1224

        {
          "href": "http://example.com/api/admin/enterprises/1224", 
          "rel": "enterprise"
        }
  3. Perform a PUT request to the user but replace the enterprise id in the URL with an underscore character "_". Send the user entity that you modified above. Remember that the user entity must be complete in order to save the user, e.g. add an email attribute for the user if you didn't already add one because this is obligatory.

    curl -X PUT http://example.com/api/admin/enterprises/_/users/1179 \ 

Below is a full walkthrough of a user switching enterprise, from the current enterprise to another enterprise

 Click here to expand...

Get the user from any enterprise

curl -X GET \
  'https://example.com/api/admin/enterprises/_/users?has=cloudadmin' \
  -H 'Accept: application/vnd.abiquo.users+json;version=4.6' \

Find the appropriate user and copy the user entity.


...
        {
            "id": 10,
            "nick": "cloudadmin",
            "name": "cloudadmin",
            "surname": "cloudadmin",
            "email": "cloudadmin@example.com",
            "locale": "en_US",
            "authType": "ABIQUO",
            "active": true,
            "publicSshKey": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDgm0ckfxabLgc2a2cJlTyTdsZ4F5xNWHQqOZjOiZ/OEJ7jDXJiDz2cWiUNeNJJ49xFHHVo4R7QIROau8F5jhjvz1T6yPIcaI+EEqyKBNZtAuTxi7u9xwiuye4Zj6H37oAsxolRNBKg/nPCZ6SGNnVp2nhbN4bJS33Ia8rUSTa7yEbQxkduQndvNh64DscmxMwPiVJOcc9GJZz7gz1PcpeNNxP7Ir3giDSQF+TP4OyCDYV8nOQitGbxqNlJK3jcrx4nhaaY9As1xb5XD1e6X40fNg2+aW6z5rTh5PaEqPReyHDf7RxFWsgj58XUiJ4EPKvnV2EqM9DQINahlDlvIVG8G7p1dx+zT9VCZjEaHIuMQvK7MhStI9cE++TxhipPRfpPClDVQMguDs/JBpiztDZyCYe8szBo+IfxWl3im3pO4CjHqns1Kq0qR8AE7hc3wzNxR4wtX/jGN22LUDObfjVO3zYvnlDu9B3iTtFhS8MZ1N4Pk2/DKnN2/qg8nSNCufSZcFHnY2OV4Wspl5S5MIvz8nQMcl+0q+0BELeIdA0zhAzAaJMv0P8C/R9L0HVLCUFmzwIPW8rrEox5WgZjbxh5Fw3gDNk8/vCWZsKWsYFyy1MoFPt9JrfrO1/axb3xowFI04FcaXgk69SAMxfzL4LQuFCimprdj0gAea1gyswLvw== maryjane.smyth@abiquo.com",
            "firstLogin": false,
            "locked": false,
            "links": [
                {
                    "title": "Usr_mg_roles",
                    "rel": "enterprise",
                    "type": "application/vnd.abiquo.enterprise+json",
                    "href": "https://example.com:443/api/admin/enterprises/275"
                },
                {
                    "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/275/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/275/users/10/action/virtualmachines"
                },
                {
                    "title": "pending tasks",
                    "rel": "pendingtasks",
                    "type": "application/vnd.abiquo.tasks+json",
                    "href": "https://example.com:443/api/admin/enterprises/275/users/10/action/pendingtasks"
                },
                {
                    "title": "applications",
                    "rel": "applications",
                    "type": "application/vnd.abiquo.applications+json",
                    "href": "https://example.com:443/api/admin/enterprises/275/users/10/applications"
                },
                {
                    "title": "enable two factor authentication",
                    "rel": "enable2fa",
                    "type": "application/vnd.abiquo.twofactorauthcredentials+json",
                    "href": "https://example.com:443/api/admin/enterprises/275/users/10/action/enable2fa"
                },
                {
                    "title": "async tasks",
                    "rel": "asynctasks",
                    "type": "application/vnd.abiquo.asynctasks+json",
                    "href": "https://example.com:443/api/admin/enterprises/275/users/10/asynctasks"
                }
            ]
        }
...

Edit the user entity to remove the link to the current enterprise and add the link to the new enterprise. Here we have changed the enterprise link to 276

Note that the "title" and "type" attributes of the link are not necessary for this request.

        {
            "id": 10,
            "nick": "cloudadmin",
            "name": "cloudadmin",
            "surname": "cloudadmin",
            "email": "cloudadmin@example.com",
            "locale": "en_US",
            "authType": "ABIQUO",
            "active": true,
            "publicSshKey": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDgm0ckfxabLgc2a2cJlTyTdsZ4F5xNWHQqOZjOiZ/OEJ7jDXJiDz2cWiUNeNJJ49xFHHVo4R7QIROau8F5jhjvz1T6yPIcaI+EEqyKBNZtAuTxi7u9xwiuye4Zj6H37oAsxolRNBKg/nPCZ6SGNnVp2nhbN4bJS33Ia8rUSTa7yEbQxkduQndvNh64DscmxMwPiVJOcc9GJZz7gz1PcpeNNxP7Ir3giDSQF+TP4OyCDYV8nOQitGbxqNlJK3jcrx4nhaaY9As1xb5XD1e6X40fNg2+aW6z5rTh5PaEqPReyHDf7RxFWsgj58XUiJ4EPKvnV2EqM9DQINahlDlvIVG8G7p1dx+zT9VCZjEaHIuMQvK7MhStI9cE++TxhipPRfpPClDVQMguDs/JBpiztDZyCYe8szBo+IfxWl3im3pO4CjHqns1Kq0qR8AE7hc3wzNxR4wtX/jGN22LUDObfjVO3zYvnlDu9B3iTtFhS8MZ1N4Pk2/DKnN2/qg8nSNCufSZcFHnY2OV4Wspl5S5MIvz8nQMcl+0q+0BELeIdA0zhAzAaJMv0P8C/R9L0HVLCUFmzwIPW8rrEox5WgZjbxh5Fw3gDNk8/vCWZsKWsYFyy1MoFPt9JrfrO1/axb3xowFI04FcaXgk69SAMxfzL4LQuFCimprdj0gAea1gyswLvw== maryjane.smyth@abiquo.com",
            "firstLogin": false,
            "locked": false,
            "links": [
                {
                    "rel": "enterprise",
                    "href": "https://example.com:443/api/admin/enterprises/275"
                },
                {
                    "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/275/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/275/users/10/action/virtualmachines"
                },
                {
                    "title": "pending tasks",
                    "rel": "pendingtasks",
                    "type": "application/vnd.abiquo.tasks+json",
                    "href": "https://example.com:443/api/admin/enterprises/275/users/10/action/pendingtasks"
                },
                {
                    "title": "applications",
                    "rel": "applications",
                    "type": "application/vnd.abiquo.applications+json",
                    "href": "https://example.com:443/api/admin/enterprises/275/users/10/applications"
                },
                {
                    "title": "enable two factor authentication",
                    "rel": "enable2fa",
                    "type": "application/vnd.abiquo.twofactorauthcredentials+json",
                    "href": "https://example.com:443/api/admin/enterprises/275/users/10/action/enable2fa"
                },
                {
                    "title": "async tasks",
                    "rel": "asynctasks",
                    "type": "application/vnd.abiquo.asynctasks+json",
                    "href": "https://example.com:443/api/admin/enterprises/275/users/10/asynctasks"
                }
            ]
        }

To update the user to switch enterprises, perform a put request with the above user entity

curl -X PUT \
  https://example.com/api/admin/enterprises/_/users/10 \
  -H 'Accept: application/vnd.abiquo.user+json;version=4.6' \
  -H 'Content-Type: application/vnd.abiquo.user+json;version=4.6' \
  -u user:password --verbose \
  -d @requestpayload.json 

Request payload

{
            "id": 10,
            "nick": "cloudadmin",
            "name": "cloudadmin",
            "surname": "cloudadmin",
            "email": "cloudadmin@example.com",
            "locale": "en_US",
            "authType": "ABIQUO",
            "active": true,
            "publicSshKey": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDgm0ckfxabLgc2a2cJlTyTdsZ4F5xNWHQqOZjOiZ/OEJ7jDXJiDz2cWiUNeNJJ49xFHHVo4R7QIROau8F5jhjvz1T6yPIcaI+EEqyKBNZtAuTxi7u9xwiuye4Zj6H37oAsxolRNBKg/nPCZ6SGNnVp2nhbN4bJS33Ia8rUSTa7yEbQxkduQndvNh64DscmxMwPiVJOcc9GJZz7gz1PcpeNNxP7Ir3giDSQF+TP4OyCDYV8nOQitGbxqNlJK3jcrx4nhaaY9As1xb5XD1e6X40fNg2+aW6z5rTh5PaEqPReyHDf7RxFWsgj58XUiJ4EPKvnV2EqM9DQINahlDlvIVG8G7p1dx+zT9VCZjEaHIuMQvK7MhStI9cE++TxhipPRfpPClDVQMguDs/JBpiztDZyCYe8szBo+IfxWl3im3pO4CjHqns1Kq0qR8AE7hc3wzNxR4wtX/jGN22LUDObfjVO3zYvnlDu9B3iTtFhS8MZ1N4Pk2/DKnN2/qg8nSNCufSZcFHnY2OV4Wspl5S5MIvz8nQMcl+0q+0BELeIdA0zhAzAaJMv0P8C/R9L0HVLCUFmzwIPW8rrEox5WgZjbxh5Fw3gDNk8/vCWZsKWsYFyy1MoFPt9JrfrO1/axb3xowFI04FcaXgk69SAMxfzL4LQuFCimprdj0gAea1gyswLvw== maryjane.smyth@abiquo.com",
            "firstLogin": false,
            "locked": false,
            "links": [
                {
                    "rel": "enterprise",
                    "href": "https://example.com:443/api/admin/enterprises/276"
                },
                {
                    "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/275/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/275/users/10/action/virtualmachines"
                },
                {
                    "title": "pending tasks",
                    "rel": "pendingtasks",
                    "type": "application/vnd.abiquo.tasks+json",
                    "href": "https://example.com:443/api/admin/enterprises/275/users/10/action/pendingtasks"
                },
                {
                    "title": "applications",
                    "rel": "applications",
                    "type": "application/vnd.abiquo.applications+json",
                    "href": "https://example.com:443/api/admin/enterprises/275/users/10/applications"
                },
                {
                    "title": "enable two factor authentication",
                    "rel": "enable2fa",
                    "type": "application/vnd.abiquo.twofactorauthcredentials+json",
                    "href": "https://example.com:443/api/admin/enterprises/275/users/10/action/enable2fa"
                },
                {
                    "title": "async tasks",
                    "rel": "asynctasks",
                    "type": "application/vnd.abiquo.asynctasks+json",
                    "href": "https://example.com:443/api/admin/enterprises/275/users/10/asynctasks"
                }
            ]
        }



Copyright © 2006-2022, Abiquo Holdings SL. All rights reserved