2017-07-30 64 views
-1

我正在计算每个子帐户有多少项目和费用。我读了这篇文章。它显示使用“getNextInvoiceTopLevelBillingItems”(http://knowledgelayer.softlayer.com/procedure/how-extract-user-billing-information-using-softlayers-api)。用户可以获得发票吗?

但是,开票项目不像发票。例如,计费项目只显示vCPU总量,不显示RAM和DISK和NIC数量。如果我希望获得所有发票,则该函数将是SoftLayer_Account下的getInvoices。

可以将billing_items与发票相关吗?或者只是抓住所有发票,但发票与用户有什么关系?

回答

0

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

如果您希望获得账户中所有发票的相同信息,则需要使用getInvoices方法使用相同的方法,但首先您需要了解其结构。 A 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) 
相关问题