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

时间:2017-07-30 08:47:53

标签: python ibm-cloud ibm-cloud-infrastructure billing invoice

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

但是,结算项目与发票不同。例如,计费项目仅显示vCPU总金额,而不显示RAM和DISK以及NIC金额。如果我想获得所有发票,则该功能将是SoftLayer_Account下的getInvoices。

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

1 个答案:

答案 0 :(得分:0)

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

如果您希望获取帐户中所有发票的相同信息,则需要使用getInvoices方法使用相同的想法,但首先您需要了解其结构。 Softlayer_Billing_Invoice对象有一个SoftLayer_Billing_Invoice_Item项列表,每个项都与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)