是否有可能获得用户的发票?

Is that possible to get invoices by users?

我正在尝试计算每个子帐户的商品数量和费用。我读了这篇文章。它显示使用 "getNextInvoiceTopLevelBillingItems" (http://knowledgelayer.softlayer.com/procedure/how-extract-user-billing-information-using-softlayers-api).

但是,账单项目不像发票。例如,billing item 只显示 vCPU 总量,不显示 RAM 和 DISK 以及 NIC 数量。如果我想获取所有发票,函数将是 SoftLayer_Account.

下的 getInvoices

可以billing_items与发票相关吗?或者只获取所有发票,但发票如何与用户相关?

是的,他们可以。您阅读的文章允许了解下一张发票上每个 SoftLayer_Billing_ItemtotalRecurringAmount 和关联的 user。考虑到发票中的项目可能已由不同的用户订购。

如果您想获得帐户中所有发票的相同信息,您需要通过使用 getInvoices method but first you need to understand how it is structured. A Softlayer_Billing_Invoice object has a list of SoftLayer_Billing_Invoice_Item items and each one is associated to a SoftLayer_Billing_item 对象来使用相同的想法,如您所见,这就是您要求的关系。

下面是您可以用来获取与每张发票上的用户关联的计费项目的对象掩码,这使用 getInvoices 方法:

object_mask="mask[id,items[id,description,billingItem[id,orderItem[id,order[id,status,userRecord[id,firstName,lastName]]],invoiceItem[id,totalRecurringAmount]]]]"

但请注意,一张发票可能包含成百上千个项目,您可能会因此超时或服务器内部错误。为了避免它们,我建议您使用 result limits.

下面是 python 中的完整示例。

import SoftLayer
from pprint import pprint as pp

user_name = 'set-me'
user_key = 'set-me'    

client = SoftLayer.create_client_from_env(username=user_name, api_key=user_key)

object_mask = "mask[id,items[id,description,billingItem[id,orderItem[id," \
              "order[id,status,userRecord[id,firstName,lastName]]]," \
              "invoiceItem[id,totalRecurringAmount]]]]";

user_bill = client['Account'].getInvoices(mask=object_mask, limit=10, offset=0)

pp(user_bill)