是否有可用于检索账户名称的IBM Cloud API调用?
解决方法
可以通过API直接获取账户名称,无需调用ibmcloud CLI,具体实现方式如下:
调用SoftLayer API的SoftLayer_Account服务getObject方法,通过对象掩码指定返回companyName字段,该字段与控制台「Manage > Account > Account Settings」页面展示的账户名称完全对应。
Python 示例代码
import SoftLayer # 初始化客户端,可提前通过环境变量或配置文件配置API密钥,也可直接在参数中传入 client = SoftLayer.Client( username='你的SoftLayer用户名', api_key='你的SoftLayer API密钥' ) # 指定返回掩码,获取账户ID和账户名称 account_data = client['SoftLayer_Account'].getObject(mask='mask[id, companyName]') account_id = account_data['id'] account_name = account_data['companyName']
你之前没有找到对应返回字段,是因为SoftLayer_Account::getObject默认不会返回全量属性,需要通过mask主动指定所需字段即可实现需求。
内容的提问来源于stack exchange,提问作者Bill
相关产品推荐
相关产品推荐

