Create Google Cloud Usage Cost config

POST https://api.ap1.datadoghq.com/api/v2/cost/gcp_uc_confighttps://api.ap2.datadoghq.com/api/v2/cost/gcp_uc_confighttps://api.datadoghq.eu/api/v2/cost/gcp_uc_confighttps://api.ddog-gov.com/api/v2/cost/gcp_uc_confighttps://api.us2.ddog-gov.com/api/v2/cost/gcp_uc_confighttps://api.datadoghq.com/api/v2/cost/gcp_uc_confighttps://api.us3.datadoghq.com/api/v2/cost/gcp_uc_confighttps://api.us5.datadoghq.com/api/v2/cost/gcp_uc_config

Overview

Create a Cloud Cost Management account for an Google Cloud Usage Cost config. This endpoint requires the cloud_cost_management_write permission.

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

Request

Body Data (required)

Expand All

Field

Type

Description

data [required]

object

Google Cloud Usage Cost config post data.

attributes

object

Attributes for Google Cloud Usage Cost config post request.

billing_account_id [required]

string

The Google Cloud account ID.

bucket_name [required]

string

The Google Cloud bucket name used to store the Usage Cost export.

export_dataset_name [required]

string

The export dataset name used for the Google Cloud Usage Cost report.

export_prefix

string

The export prefix used for the Google Cloud Usage Cost report.

export_project_name [required]

string

The name of the Google Cloud Usage Cost report.

service_account [required]

string

The unique Google Cloud service account email.

type [required]

enum

Type of Google Cloud Usage Cost config post request. Allowed enum values: gcp_uc_config_post_request

default: gcp_uc_config_post_request

{
  "data": {
    "attributes": {
      "billing_account_id": "123456_A123BC_12AB34",
      "bucket_name": "dd-cost-bucket",
      "export_dataset_name": "billing",
      "export_prefix": "datadog_cloud_cost_usage_export",
      "export_project_name": "dd-cloud-cost-report",
      "service_account": "dd-ccm-gcp-integration@my-environment.iam.gserviceaccount.com"
    },
    "type": "gcp_uc_config_post_request"
  }
}

Response

OK

Response of Google Cloud Usage Cost config.

Expand All

Field

Type

Description

data

object

Google Cloud Usage Cost config.

attributes [required]

object

Attributes for a Google Cloud Usage Cost config.

account_id [required]

string

The Google Cloud account ID.

bucket_name [required]

string

The Google Cloud bucket name used to store the Usage Cost export.

created_at

string

The timestamp when the Google Cloud Usage Cost config was created.

dataset [required]

string

The export dataset name used for the Google Cloud Usage Cost Report.

error_messages

[string]

The error messages for the Google Cloud Usage Cost config.

export_prefix [required]

string

The export prefix used for the Google Cloud Usage Cost Report.

export_project_name [required]

string

The name of the Google Cloud Usage Cost Report.

months

int32

DEPRECATED: The number of months the report has been backfilled.

project_id

string

The project_id of the Google Cloud Usage Cost report.

service_account [required]

string

The unique Google Cloud service account email.

status [required]

string

The status of the Google Cloud Usage Cost config.

status_updated_at

string

The timestamp when the Google Cloud Usage Cost config status was updated.

updated_at

string

The timestamp when the Google Cloud Usage Cost config status was updated.

id

string

The ID of the Google Cloud Usage Cost config.

type [required]

enum

Type of Google Cloud Usage Cost config. Allowed enum values: gcp_uc_config

default: gcp_uc_config

{
  "data": {
    "attributes": {
      "account_id": "123456_A123BC_12AB34",
      "bucket_name": "dd-cost-bucket",
      "created_at": "string",
      "dataset": "billing",
      "error_messages": [],
      "export_prefix": "datadog_cloud_cost_usage_export",
      "export_project_name": "dd-cloud-cost-report",
      "months": "integer",
      "project_id": "my-project-123",
      "service_account": "dd-ccm-gcp-integration@my-environment.iam.gserviceaccount.com",
      "status": "active",
      "status_updated_at": "string",
      "updated_at": "string"
    },
    "id": "string",
    "type": "gcp_uc_config"
  }
}

Bad Request

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

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

Forbidden

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

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

Too many requests

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

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

Code Example

                          ## default
# 

# Curl command
curl -X POST "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/gcp_uc_config" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -H "DD-API-KEY: ${DD_API_KEY}" \ -H "DD-APPLICATION-KEY: ${DD_APP_KEY}" \ -d @- << EOF { "data": { "attributes": { "billing_account_id": "123456_A123BC_12AB34", "bucket_name": "dd-cost-bucket", "export_dataset_name": "billing", "export_prefix": "datadog_cloud_cost_usage_export", "export_project_name": "dd-cloud-cost-report", "service_account": "dd-ccm-gcp-integration@my-environment.iam.gserviceaccount.com" }, "type": "gcp_uc_config_post_request" } } EOF
// Create Google Cloud Usage Cost config 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() {
	body := datadogV2.GCPUsageCostConfigPostRequest{
		Data: datadogV2.GCPUsageCostConfigPostData{
			Attributes: &datadogV2.GCPUsageCostConfigPostRequestAttributes{
				BillingAccountId:  "123456_A123BC_12AB34",
				BucketName:        "dd-cost-bucket",
				ExportDatasetName: "billing",
				ExportPrefix:      datadog.PtrString("datadog_cloud_cost_usage_export"),
				ExportProjectName: "dd-cloud-cost-report",
				ServiceAccount:    "dd-ccm-gcp-integration@my-environment.iam.gserviceaccount.com",
			},
			Type: datadogV2.GCPUSAGECOSTCONFIGPOSTREQUESTTYPE_GCP_USAGE_COST_CONFIG_POST_REQUEST,
		},
	}
	ctx := datadog.NewDefaultContext(context.Background())
	configuration := datadog.NewConfiguration()
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV2.NewCloudCostManagementApi(apiClient)
	resp, r, err := api.CreateCostGCPUsageCostConfig(ctx, body)

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

	responseContent, _ := json.MarshalIndent(resp, "", "  ")
	fmt.Fprintf(os.Stdout, "Response from `CloudCostManagementApi.CreateCostGCPUsageCostConfig`:\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"
// Create Google Cloud Usage Cost config 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.GCPUsageCostConfigPostData;
import com.datadog.api.client.v2.model.GCPUsageCostConfigPostRequest;
import com.datadog.api.client.v2.model.GCPUsageCostConfigPostRequestAttributes;
import com.datadog.api.client.v2.model.GCPUsageCostConfigPostRequestType;
import com.datadog.api.client.v2.model.GCPUsageCostConfigResponse;

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

    GCPUsageCostConfigPostRequest body =
        new GCPUsageCostConfigPostRequest()
            .data(
                new GCPUsageCostConfigPostData()
                    .attributes(
                        new GCPUsageCostConfigPostRequestAttributes()
                            .billingAccountId("123456_A123BC_12AB34")
                            .bucketName("dd-cost-bucket")
                            .exportDatasetName("billing")
                            .exportPrefix("datadog_cloud_cost_usage_export")
                            .exportProjectName("dd-cloud-cost-report")
                            .serviceAccount(
                                "dd-ccm-gcp-integration@my-environment.iam.gserviceaccount.com"))
                    .type(GCPUsageCostConfigPostRequestType.GCP_USAGE_COST_CONFIG_POST_REQUEST));

    try {
      GCPUsageCostConfigResponse result = apiInstance.createCostGCPUsageCostConfig(body);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println(
          "Exception when calling CloudCostManagementApi#createCostGCPUsageCostConfig");
      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"
"""
Create Google Cloud Usage Cost config returns "OK" response
"""

from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.cloud_cost_management_api import CloudCostManagementApi
from datadog_api_client.v2.model.gcp_usage_cost_config_post_data import GCPUsageCostConfigPostData
from datadog_api_client.v2.model.gcp_usage_cost_config_post_request import GCPUsageCostConfigPostRequest
from datadog_api_client.v2.model.gcp_usage_cost_config_post_request_attributes import (
    GCPUsageCostConfigPostRequestAttributes,
)
from datadog_api_client.v2.model.gcp_usage_cost_config_post_request_type import GCPUsageCostConfigPostRequestType

body = GCPUsageCostConfigPostRequest(
    data=GCPUsageCostConfigPostData(
        attributes=GCPUsageCostConfigPostRequestAttributes(
            billing_account_id="123456_A123BC_12AB34",
            bucket_name="dd-cost-bucket",
            export_dataset_name="billing",
            export_prefix="datadog_cloud_cost_usage_export",
            export_project_name="dd-cloud-cost-report",
            service_account="dd-ccm-gcp-integration@my-environment.iam.gserviceaccount.com",
        ),
        type=GCPUsageCostConfigPostRequestType.GCP_USAGE_COST_CONFIG_POST_REQUEST,
    ),
)

configuration = Configuration()
with ApiClient(configuration) as api_client:
    api_instance = CloudCostManagementApi(api_client)
    response = api_instance.create_cost_gcp_usage_cost_config(body=body)

    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"
# Create Google Cloud Usage Cost config returns "OK" response

require "datadog_api_client"
api_instance = DatadogAPIClient::V2::CloudCostManagementAPI.new

body = DatadogAPIClient::V2::GCPUsageCostConfigPostRequest.new({
  data: DatadogAPIClient::V2::GCPUsageCostConfigPostData.new({
    attributes: DatadogAPIClient::V2::GCPUsageCostConfigPostRequestAttributes.new({
      billing_account_id: "123456_A123BC_12AB34",
      bucket_name: "dd-cost-bucket",
      export_dataset_name: "billing",
      export_prefix: "datadog_cloud_cost_usage_export",
      export_project_name: "dd-cloud-cost-report",
      service_account: "dd-ccm-gcp-integration@my-environment.iam.gserviceaccount.com",
    }),
    type: DatadogAPIClient::V2::GCPUsageCostConfigPostRequestType::GCP_USAGE_COST_CONFIG_POST_REQUEST,
  }),
})
p api_instance.create_cost_gcp_usage_cost_config(body)

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"
// Create Google Cloud Usage Cost config returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_cloud_cost_management::CloudCostManagementAPI;
use datadog_api_client::datadogV2::model::GCPUsageCostConfigPostData;
use datadog_api_client::datadogV2::model::GCPUsageCostConfigPostRequest;
use datadog_api_client::datadogV2::model::GCPUsageCostConfigPostRequestAttributes;
use datadog_api_client::datadogV2::model::GCPUsageCostConfigPostRequestType;

#[tokio::main]
async fn main() {
    let body = GCPUsageCostConfigPostRequest::new(
        GCPUsageCostConfigPostData::new(
            GCPUsageCostConfigPostRequestType::GCP_USAGE_COST_CONFIG_POST_REQUEST,
        )
        .attributes(
            GCPUsageCostConfigPostRequestAttributes::new(
                "123456_A123BC_12AB34".to_string(),
                "dd-cost-bucket".to_string(),
                "billing".to_string(),
                "dd-cloud-cost-report".to_string(),
                "dd-ccm-gcp-integration@my-environment.iam.gserviceaccount.com".to_string(),
            )
            .export_prefix("datadog_cloud_cost_usage_export".to_string()),
        ),
    );
    let configuration = datadog::Configuration::new();
    let api = CloudCostManagementAPI::with_config(configuration);
    let resp = api.create_cost_gcp_usage_cost_config(body).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
/**
 * Create Google Cloud Usage Cost config returns "OK" response
 */

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

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

const params: v2.CloudCostManagementApiCreateCostGCPUsageCostConfigRequest = {
  body: {
    data: {
      attributes: {
        billingAccountId: "123456_A123BC_12AB34",
        bucketName: "dd-cost-bucket",
        exportDatasetName: "billing",
        exportPrefix: "datadog_cloud_cost_usage_export",
        exportProjectName: "dd-cloud-cost-report",
        serviceAccount:
          "dd-ccm-gcp-integration@my-environment.iam.gserviceaccount.com",
      },
      type: "gcp_uc_config_post_request",
    },
  },
};

apiInstance
  .createCostGCPUsageCostConfig(params)
  .then((data: v2.GCPUsageCostConfigResponse) => {
    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"