Updated on 2024-07-05 GMT+08:00

Querying Cost Data

Function

This API is used to query the cost data on the self-built platform.

Note:

This API can be invoked using the customer AK/SK or token.

The data of the previous month is available after the bill is generated.

Debugging

You can debug this API API Explorer.

URI

POST /v4/costs/cost-analysed-bills/query

Table 1 Header parameters

Parameter

Mandatory

Value Range

Description

X-Language

No

A maximum of 8 characters

Language.

  • zh_CN: Chinese
  • en_US: English

Default value: zh_CN

Request

Request Parameters

Parameter

Mandatory

Type

Value Range

Description

time_condition

Yes

TimeCondition Object

-

Time condition. For details, see Table 2.

groupby

Yes

List<GroupBy>

A maximum of 2 values

Search dimension. For details, see Table 3.

NOTE:

If there are two values for this parameter, the values must be a combination of tag, cost_unit, and dimension, or both of these two values are set to dimension.

cost_type

Yes

String

A maximum of 256 characters

Cost type.

  • ORIGINAL_COST: Original cost
  • AMORTIZED_COST: Amortized cost

amount_type

Yes

String

  

Amount type.

  • PAYMENT_AMOUNT
  • NET_AMOUNT.

filters

No

List<Filter>

Minimum length: 0 characters

Maximum length: 100 characters

Filter. For details, see Table 4.

If this parameter is not included in the request parameters, is left empty, or is set to null, it cannot be used as a filter criterion.

offset

No

Integer

[0-200000]

Offset, starting from 0. The default value is 0.

NOTE:

This parameter is used for pagination. Use the default value 0 if pagination is not required. offset indicates the offset relative to the first data record that meets the conditions. If you set offset to 1, the second and subsequent data records will be returned.

For example, there are 10 data records, and if you set limit to 10 and offset to 1, the second to the tenth data records will be returned.

limit

No

Integer

[1,1000]

Number of records queried each time. The default value is 10.

Table 2 TimeCondition

Parameter

Mandatory

Type

Value Range

Description

time_measure_id

Yes

Integer

[1,2]

Time unit.

  • 1: Day
  • 2: Month

begin_time

Yes

String

32

Start date (GMT+08:00).

  • If the value for time_measure_id is 1, the date is in YYYY-MM-DD format.
  • If the value for time_measure_id is 2, the date is in YYYY-MM format.

end_time

Yes

String

32

End date (GMT+08:00).

  • If the value for time_measure_id is 1, the date is in YYYY-MM-DD format.
  • If the value for time_measure_id is 2, the date is in YYYY-MM format.
NOTICE:

Only the cost data within 18 months can be queried.

Table 3 GroupBy

Parameter

Mandatory

Type

Value Range

Description

type

Yes

String

A maximum of 64 characters

  • tag: Grouped by cost tags
  • cost_unit: Grouped by cost categories
  • dimension: Default value

key

Yes

String

A maximum of 128 characters

  • If type is set to tag, the value for this parameter is the key of the tag.
  • If type is set to cost_unit, set this parameter to the key of cost_unit.
  • If type is set to dimension, the value options are as follows:
    • CLOUD_SERVICE_TYPE: Service type
    • ASSOCIATED_ACCOUNT: Linked account
      NOTE:

      An enterprise master account that has the permission to view the expenditure data of its associated member accounts can view the cost data of the member accounts.

    • REGION_CODE: Region
    • RES_SPEC_CODE: Specification code
    • USAGE_TYPE: Usage type
    • ENTERPRISE_PROJECT_ID: Enterprise project
    • RESOURCE_ID: Resource
    • CHARGING_MODE: Billing mode
    • BILL_TYPE: bill type
    • RESOURCE_TYPE: Resource type
    • AZ_CODE: AZ
    • BE_ID: Business entity
    • PAYER_ACCOUNT_ID: Payer account
    • SPLIT_ITEM_NAME: split item
Table 4 Filter

Parameter

Mandatory

Type

Value Range

Description

operator

Yes

Integer

[0-1]

Operator.

  • 0: Only contains
  • 1: Only excludes

filter_factor

Yes

FilterFactor Object

-

Filter factor. For details, see Table 5.

Table 5 FilterFactor

Parameter

Mandatory

Type

Value Range

Description

key

Yes

String

A maximum of 256 characters

Grouping conditions.

  • CLOUD_SERVICE_TYPE: Service type
  • ASSOCIATED_ACCOUNT: Linked account
    NOTE:

    Set this parameter to the HUAWEI ID of the associated account.

    An enterprise master account that has the permission to view the expenditure data of its associated member accounts can view the cost data of the member accounts.

  • REGION_CODE: Region
  • RES_SPEC_CODE: Specification code
  • USAGE_TYPE: Usage type
  • ENTERPRISE_PROJECT_ID: Enterprise project
  • RESOURCE_ID: Resource
  • CHARGING_MODE: Billing mode
  • BILL_TYPE: bill type.
  • RESOURCE_TYPE: Resource type
  • AZ_CODE: AZ
  • BE_ID: Business entity
  • PAYER_ACCOUNT_ID: Payer account
  • RESOURCE_TAG: Cost tag
  • COST_UNIT: Cost category
  • SPLIT_ITEM_NAME: split item
    NOTE:

    When the cost type is ORIGINAL_COST, split items cannot be used to query costs.

value

Yes

List<String>

Minimum count: 1

Maximum count: 100

Filter value.

Example Request

POST https://bss-intl.myhuaweicloud.com/v4/costs/cost-analysed-bills/query HTTP/1.1
Content-Type: application/json
X-Auth-Token: MIIPAgYJKoZIhvcNAQcCo...ggg1BBIINPXsidG9rZ
{
	"amount_type": "PAYMENT_AMOUNT",
	"offset": 0,
	"cost_type": "ORIGINAL_COST",
	"limit": 10,
	"groupby": [{
		"type": "dimension",
		"key": "CLOUD_SERVICE_TYPE"
	}],
	"filters": [{
		"filter_factor": {
			"value": ["cn-north-1"],
			"key": "REGION_CODE"
		},
		"operator": 0
	}],
	"time_condition": {
		"end_time": "2021-07-15",
		"begin_time": "2021-07-14",
		"time_measure_id": 1
	}
}

Response Message

Response Parameters

Parameter

Type

Value Range

Description

error_code

String

A maximum of 20 characters

Returned value. For details, see Returned Values. This parameter is returned only when the query failed.

error_msg

String

A maximum of 1000 characters

Error description. This parameter is returned only when the query failed.

currency

String

A maximum of 8 characters

Currency.

  • USD

total_count

Integer

-

Total number of records.

cost_data

List<CostDataByDimension>

-

Cost details by day or month. For details, see Table 6.

Table 6 CostDataByDimension

Parameter

Type

Value Range

Description

dimensions

List<DimensionGroup>

A maximum of 1 value

Dimensions. For details, see Table 7.

costs

List<Cost>

Max Count: 10000

Cost value. For details, see Table 8.

amount_by_costs

String

A maximum of 64 characters

Total cost in a period.

official_amount_by_costs

String

A maximum of 64 characters

Total expenditures based on list prices in a period.

Table 7 DimensionGroup

Parameter

Type

Value Range

Description

key

String

A maximum of 128 characters

Grouping conditions

  • CLOUD_SERVICE_TYPE: Service type
  • ENTERPRISE_PROJECT_ID: Enterprise project
  • USAGE_TYPE: Usage type
  • RESOURCE_TYPE: Resource type
  • AZ_CODE: AZ
  • BILL_TYPE: Bill type
  • ASSOCIATED_ACCOUNT: Linked account
  • RES_SPEC_CODE: Specification Code
  • BE_ID: Business entity
  • REGION_CODE: Region
  • CHARGING_MODE: Billing mode
  • PAYER_ACCOUNT_ID: Payer account
  • RESOURCE_TAG: Resource tag
  • RESOURCE_ID: Resource ID
  • COST_UNIT: Cost category
  • SPLIT_ITEM_NAME: Split item

value

String

-

Dimension.

Table 8 Cost

Parameter

Type

Value Range

Description

time_dimension_value

String

A maximum of 20 characters

Time dimension.

  • yyyy-mm-dd indicates that data is filtered by day.
  • yyyy-mm indicates that data is filtered by month.

time_measure_id

Int

-

Time unit.

  • 1: Day
  • 2: Month

amount

String

A maximum of 64 characters

One of the following cost types: original costs, net original costs, amortized costs, and net amortized costs.

official_amount

String

A maximum of 64 characters

List price.

Example Response

HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Content-Length: length
Date: response time 
{
    "currency": "USD",
    "total_count": 1,
    "cost_data": [
        {
            "dimensions": [
                {
                    "key": "tag",
                    "value": "Group:noTagKey"
                }
            ],
            "costs": [
                {
                    "time_dimension_value": "2021-08",
                    "time_measure_id": 2,
                    "amount": "13225.00",
                    "official_amount": "13225.00"
                }
            ],
            "amount_by_costs": "13225.00",
            "official_amount_by_costs": "13225.00"
        }
    ]
}

Returned Values

  • 4xx: This class of HTTP status code is intended for situations in which the error seems to have been caused by the client, for example, the request contains bad syntax or incorrect parameters. You must ensure the request is correct.
  • 5xx: This class of HTTP status code is intended for cases in which the Huawei Cloud server is aware that it has encountered an error or is otherwise incapable of performing the request. In this case, contact Huawei Cloud customer service.

HTTP Value

Error Code

Description

400

CBC.0100

Invalid parameter.

400

CBC.18000014

Cost Center not enabled.

400

CBC.18000016

Insufficient permissions. Contact your partner.

400

CBC.18000030

The cost data of accounts that are not associated with an enterprise master account cannot be queried.

400

CBC.18000053

Insufficient permissions. Contact your enterprise master.

500

CBC.0999

Other errors.

400

CBC.18000048

Too many independent accounting members. Specify a member account for query.