如何在 Softlayer 中使用 getAllOwnedAccounts()

How to use getAllOwnedAccounts() in Softlayer

我正在使用 Softlayer java 客户端库开发云门户。

我的用户 ID 是一个主帐户,就在品牌之下,并使用 createCustomerAccount() 创建了帐户。创建帐户后,我无法使用 getAllOwnedAccounts() 检索帐户列表。执行下面的代码后只能显示我的帐户。其他账号已创建成功,可以在"agent.softlayer.com".

上找到账号

这是我的代码..

@Test
    public void testConnect() throws Exception {

        ApiClient client = new RestApiClient().withCredentials(userId, apiKey);

        Brand brand = Account.service(client).getBrand();

        List<Account> accountList = Brand.service(client, brand.getId()).getAllOwnedAccounts();

        for (Account account : accountList) {
            System.out.println(account.getCompanyName() + ", state : "+ account.getState());
        }
    }

这是另一个代码..


Brand brand = Account.service(client).getBrand();

Brand.Service brdSrv = Brand.service(client, brand.getId());

brdSrv.withMask().allOwnedAccounts();

Brand brd = brdSrv.getObject();

List<Account> accountList = brd.getAllOwnedAccounts();

此代码也不起作用..

期待您的反馈。 谢谢

麦克

试试这个代码在 Python:

import SoftLayer.API

USERNAME = 'set me'
API_KEY = 'set me'

client = SoftLayer.create_client_from_env(username=USERNAME, api_key=API_KEY)

accountService = client['SoftLayer_Account']
brandService = client['SoftLayer_Brand']

# Getting the brands
brands = accountService.getOwnedBrands()
for brand in brands:
    brandId = brand['id']
    # Getting the owned Accounts
    accounts = brandService.getAllOwnedAccounts(id=brandId)
    for account in accounts:
        print(account['companyName'])

我认为问题在于您没有使用正确的品牌 ID。