Sending AnyCost Stream Data to CloudZero
An AnyCost Stream Adaptor sends Common Bill Format (CBF) data to the CloudZero /v2/connections/billing/anycost/{connection_id}/billing_drops
API by creating a billing drop where the data is uploaded. You must map the CBF data into a JSON request body.
To send AnyCost Stream data to CloudZero, complete the following steps:
- Find the AnyCost Stream connection ID.
- Send billing data to the AnyCost Stream connection Billing Drop API.
After you have sent the data, you can retrieve it from the API.
Step 1: Find the AnyCost Stream Connection ID
After you create the AnyCost Stream connection in the CloudZero UI but before you author the Adaptor code to send billing data to the CloudZero API, you must find the connection ID.
Navigate to your CloudZero organization's Settings and select your AnyCost Stream connection from the Billing Connections table.
In the AnyCost Stream Integration details page, copy the Connection ID. It will look something like this: 1234abcd-1234-abcd-1234-abcd1234efgh
Step 2: Send Billing Data to the AnyCost Stream Connection Billing Drop API
To send the billing data to the AnyCost Stream API, you must first create a JSON request body that includes the following elements:
Map the CBF to JSON Request Body Parameters
Your Adaptor must map the CBF data to the required JSON request body parameters.
For example, in the CBF your Adaptor generates, the lineitem/id
column corresponds to the request body parameter lineitem/id
.
For a full list of data file columns, see the CBF documentation.
For example, suppose your CBF data includes the following heading and row:
lineitem/type,resource/service,resource/id,time/usage_start,cost/cost
Usage,Compute,instance-0000,2024-08-16T13:00:00Z,12
In this example, you'd create a JSON request body with the following data
array. (See Example Payload for the full request body.)
{
"data": [
{
"lineitem/type": "Usage",
"time/usage_start": "2024-08-16T13:00:00Z",
"resource/id": "instance-0000",
"resource/service": "Compute",
"cost/cost": "12"
}
]
}
Make sure the Adaptor adds an object to the data
array for each row in the CBF.
Specify the Month
In the JSON body, include the month
parameter, which is an ISO 8601 formatted datetime. All CBF data in the request body must be from the same month.
In this example, your JSON request body would now resemble the following. (See Example Payload for the full request body.)
{
"month": "2024-08-16T14:27:46+00:00",
"data": [
{
"lineitem/type": "Usage",
"time/usage_start": "2024-08-16T13:00:00Z",
"resource/id": "instance-0000",
"resource/service": "Compute",
"cost/cost": "12"
}
]
}
Specify Whether to Replace or Add Data
The API supports three types of operation
that determine how records are added and/or replaced. This allows you to upload data for either a full month or a partial month.
replace_drop
(default): Replace all existing data for the specified month. This requires you to provide the data for an entire month in a single request body.replace_hourly
: Replace only the existing data that has overlapping hours. This allows you to provide data for a partial month in a single request body.sum
: Append data to the existing data. This allows you to provide data for a partial month in a single request body.
The default operation is replace_drop
. If you don't specify a different operation, be aware that any existing records associated with the AnyCost Stream Adaptor in the specified month
will be overwritten by the records in the request body.
For all operation types, if no prior data exists, CloudZero creates a new billing drop for the specified month.
Example Payload
For this example, to upload the data for a full month and replace any existing data, the completed payload would look as follows:
{
"month": "2024-08-16T14:27:46+00:00",
"operation": "replace_drop",
"data": [
{
"lineitem/type": "Usage",
"time/usage_start": "2024-08-16T13:00:00Z",
"resource/id": "instance-0000",
"resource/service": "Compute",
"cost/cost": "12"
}
]
}
See the API Reference for instructions to send the POST
request to the AnyCost Stream Billing Drops API.
AnyCost Stream API Size Limit
The AnyCost Stream Billing Drops API currently limits the size of the uncompressed JSON body to 5MB.
How to Retrieve Data from an Existing AnyCost Stream Billing Drop
You can retrieve existing billing data for a given month by sending a GET
request to the AnyCost Stream Billing Drops API and passing the desired month as a path parameter, along with the connection ID.
Updated about 2 months ago