关于通过Softlayer Billing Invoice API获取服务器标价的技术咨询
Great question! I’ve worked extensively with SoftLayer’s billing and product APIs, so let me confirm your approach and walk you through how to pull the list price alongside the discounted rate you’re already fetching.
Your current plan to use the SoftLayer_Billing_Invoice service and its getItems method is totally on the right track—you just need to extend your request with an object mask to retrieve the associated list price data that’s linked to each invoice item.
Key Details to Know
Each SoftLayer_Billing_Invoice_Item is tied to a billingItem, which in turn connects to a productItemPrice object. This object contains both:
recurringFee: The discounted price you’re already seeing on invoiceslistPrice: The original sticker price you’re looking for
Step-by-Step Implementation
Add an Object Mask to Your
getItemsCall
When you callgetItems, include a mask that drills down to theproductItemPriceof each billing item. Here’s the mask you’ll need:mask[billingItem[productItemPrice[listPrice, recurringFee], productItem[description]]]Adding
productItem[description]will also help you easily identify which server each price corresponds to.Example Code (Using SoftLayer Python Client)
Here’s a practical snippet to fetch both prices for your server invoice items:import SoftLayer # Initialize your API client client = SoftLayer.Client(username="YOUR_SL_USERNAME", api_key="YOUR_SL_API_KEY") # Replace with a target invoice ID (you can fetch recent invoices via SoftLayer_Billing_Invoice::getInvoices if needed) target_invoice_id = 12345678 # Apply the object mask price_mask = "mask[billingItem[productItemPrice[listPrice, recurringFee], productItem[description]]]" invoice_items = client["SoftLayer_Billing_Invoice"].getItems(id=target_invoice_id, mask=price_mask) # Filter to only server-related items (adjust the filter logic based on your invoice descriptions) server_billing_items = [ item for item in invoice_items if "Server" in item["billingItem"]["productItem"]["description"] ] # Print out the results for item in server_billing_items: print(f"Server: {item['billingItem']['productItem']['description']}") print(f"Sticker Price: ${item['billingItem']['productItemPrice']['listPrice']}") print(f"Discounted Price: ${item['billingItem']['productItemPrice']['recurringFee']}\n")Adjust Filters as Needed
If your invoices include non-server items, tweak the filter to match your server-specific category codes or descriptions. For example, you could check forcategoryCode == 'server'in theproductItemobject for more precise filtering.
Confirmation of Your Initial Approach
Your idea to use the billing invoice API is solid because it directly ties each billed item to its underlying product pricing data—this is the most reliable way to get both discounted and list prices for active servers that have been invoiced.
内容的提问来源于stack exchange,提问作者ChuanWee

