Get custom allocation rule

GET https://api.ap1.datadoghq.com/api/v2/cost/arbitrary_rule/{rule_id}https://api.ap2.datadoghq.com/api/v2/cost/arbitrary_rule/{rule_id}https://api.datadoghq.eu/api/v2/cost/arbitrary_rule/{rule_id}https://api.ddog-gov.com/api/v2/cost/arbitrary_rule/{rule_id}https://api.us2.ddog-gov.com/api/v2/cost/arbitrary_rule/{rule_id}https://api.datadoghq.com/api/v2/cost/arbitrary_rule/{rule_id}https://api.us3.datadoghq.com/api/v2/cost/arbitrary_rule/{rule_id}https://api.us5.datadoghq.com/api/v2/cost/arbitrary_rule/{rule_id}

Overview

Get a specific custom allocation rule - Retrieve a specific custom allocation rule by its ID

OAuth apps require the cloud_cost_management_read authorization scope to access this endpoint.

Arguments

Path Parameters

Name

Type

Description

rule_id [required]

integer

The unique identifier of the custom allocation rule

Response

OK

The definition of ArbitraryRuleResponse object.

Expand All

Field

Type

Description

data

object

The definition of ArbitraryRuleResponseData object.

attributes

object

The definition of ArbitraryRuleResponseDataAttributes object.

costs_to_allocate [required]

[object]

The attributes costs_to_allocate.

condition [required]

string

The items condition.

tag [required]

string

The items tag.

value

string

The items value.

values

[string]

The items values.

created [required]

date-time

The attributes created.

enabled [required]

boolean

The attributes enabled.

last_modified_user_uuid [required]

string

The attributes last_modified_user_uuid.

order_id [required]

int64

The attributes order_id.

processing_status

string

The attributes processing_status.

provider [required]

[string]

The attributes provider.

rejected

boolean

The attributes rejected.

rule_name [required]

string

The attributes rule_name.

strategy [required]

object

The definition of ArbitraryRuleResponseDataAttributesStrategy object.

allocated_by

[object]

The strategy allocated_by.

allocated_tags [required]

[object]

The items allocated_tags.

key [required]

string

The items key.

value [required]

string

The items value.

percentage [required]

double

The items percentage. The numeric value format should be a 32bit float value.

allocated_by_filters

[object]

The strategy allocated_by_filters.

condition [required]

string

The items condition.

tag [required]

string

The items tag.

value

string

The items value.

values

[string]

The items values.

allocated_by_tag_keys

[string]

The strategy allocated_by_tag_keys.

based_on_costs

[object]

The strategy based_on_costs.

condition [required]

string

The items condition.

tag [required]

string

The items tag.

value

string

The items value.

values

[string]

The items values.

based_on_timeseries

object

The rule strategy based_on_timeseries.

evaluate_grouped_by_filters

[object]

The strategy evaluate_grouped_by_filters.

condition [required]

string

The items condition.

tag [required]

string

The items tag.

value

string

The items value.

values

[string]

The items values.

evaluate_grouped_by_tag_keys

[string]

The strategy evaluate_grouped_by_tag_keys.

granularity

string

The strategy granularity.

method [required]

string

The strategy method.

type [required]

string

The attributes type.

updated [required]

date-time

The attributes updated.

version [required]

int32

The attributes version.

id

string

The ArbitraryRuleResponseData id.

type [required]

enum

Arbitrary rule resource type. Allowed enum values: arbitrary_rule

default: arbitrary_rule

{
  "data": {
    "attributes": {
      "costs_to_allocate": [
        {
          "condition": "is",
          "tag": "account_id",
          "value": "123456789",
          "values": null
        },
        {
          "condition": "in",
          "tag": "environment",
          "value": "",
          "values": [
            "production",
            "staging"
          ]
        }
      ],
      "created": "2023-01-01T12:00:00Z",
      "enabled": true,
      "last_modified_user_uuid": "user-123-uuid",
      "order_id": 1,
      "provider": [
        "aws",
        "gcp"
      ],
      "rule_name": "Example custom allocation rule",
      "strategy": {
        "allocated_by_tag_keys": [
          "team",
          "environment"
        ],
        "based_on_costs": [
          {
            "condition": "is",
            "tag": "service",
            "value": "web-api",
            "values": null
          },
          {
            "condition": "not in",
            "tag": "team",
            "value": "",
            "values": [
              "legacy",
              "deprecated"
            ]
          }
        ],
        "granularity": "daily",
        "method": "proportional"
      },
      "type": "shared",
      "updated": "2023-01-01T12:00:00Z",
      "version": 1
    },
    "id": "123",
    "type": "arbitrary_rule"
  }
}

Too many requests

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Code Example

                  # Path parameters
export rule_id="CHANGE_ME"
# Curl command
curl -X GET "https://api.ap1.datadoghq.com"https://api.ap2.datadoghq.com"https://api.datadoghq.eu"https://api.ddog-gov.com"https://api.us2.ddog-gov.com"https://api.datadoghq.com"https://api.us3.datadoghq.com"https://api.us5.datadoghq.com/api/v2/cost/arbitrary_rule/${rule_id}" \ -H "Accept: application/json" \ -H "DD-API-KEY: ${DD_API_KEY}" \ -H "DD-APPLICATION-KEY: ${DD_APP_KEY}"
"""
Get custom allocation rule returns "OK" response
"""

from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.cloud_cost_management_api import CloudCostManagementApi

configuration = Configuration()
with ApiClient(configuration) as api_client:
    api_instance = CloudCostManagementApi(api_client)
    response = api_instance.get_custom_allocation_rule(
        rule_id=683,
    )

    print(response)

Instructions

First install the library and its dependencies and then save the example to example.py and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" python3 "example.py"
# Get custom allocation rule returns "OK" response

require "datadog_api_client"
api_instance = DatadogAPIClient::V2::CloudCostManagementAPI.new
p api_instance.get_custom_allocation_rule(683)

Instructions

First install the library and its dependencies and then save the example to example.rb and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" rb "example.rb"
// Get custom allocation rule returns "OK" response

package main

import (
	"context"
	"encoding/json"
	"fmt"
	"os"

	"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
	"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
)

func main() {
	ctx := datadog.NewDefaultContext(context.Background())
	configuration := datadog.NewConfiguration()
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV2.NewCloudCostManagementApi(apiClient)
	resp, r, err := api.GetCustomAllocationRule(ctx, 683)

	if err != nil {
		fmt.Fprintf(os.Stderr, "Error when calling `CloudCostManagementApi.GetCustomAllocationRule`: %v\n", err)
		fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
	}

	responseContent, _ := json.MarshalIndent(resp, "", "  ")
	fmt.Fprintf(os.Stdout, "Response from `CloudCostManagementApi.GetCustomAllocationRule`:\n%s\n", responseContent)
}

Instructions

First install the library and its dependencies and then save the example to main.go and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" go run "main.go"
// Get custom allocation rule returns "OK" response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.CloudCostManagementApi;
import com.datadog.api.client.v2.model.ArbitraryRuleResponse;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = ApiClient.getDefaultApiClient();
    CloudCostManagementApi apiInstance = new CloudCostManagementApi(defaultClient);

    try {
      ArbitraryRuleResponse result = apiInstance.getCustomAllocationRule(683L);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling CloudCostManagementApi#getCustomAllocationRule");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}

Instructions

First install the library and its dependencies and then save the example to Example.java and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" java "Example.java"
// Get custom allocation rule returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_cloud_cost_management::CloudCostManagementAPI;

#[tokio::main]
async fn main() {
    let configuration = datadog::Configuration::new();
    let api = CloudCostManagementAPI::with_config(configuration);
    let resp = api.get_custom_allocation_rule(683).await;
    if let Ok(value) = resp {
        println!("{:#?}", value);
    } else {
        println!("{:#?}", resp.unwrap_err());
    }
}

Instructions

First install the library and its dependencies and then save the example to src/main.rs and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo run
/**
 * Get custom allocation rule returns "OK" response
 */

import { client, v2 } from "@datadog/datadog-api-client";

const configuration = client.createConfiguration();
const apiInstance = new v2.CloudCostManagementApi(configuration);

const params: v2.CloudCostManagementApiGetCustomAllocationRuleRequest = {
  ruleId: 683,
};

apiInstance
  .getCustomAllocationRule(params)
  .then((data: v2.ArbitraryRuleResponse) => {
    console.log(
      "API called successfully. Returned data: " + JSON.stringify(data)
    );
  })
  .catch((error: any) => console.error(error));

Instructions

First install the library and its dependencies and then save the example to example.ts and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" tsc "example.ts"