Get cost across multi-org account.
Cost by org data for a given month becomes available no later than the 16th of the following month.
Note: This endpoint has been deprecated. Please use the new endpoint
/historical_cost
instead.
"""
Get cost across multi-org account returns "OK" response
"""fromdatetimeimportdatetimefromdateutil.relativedeltaimportrelativedeltafromdatadog_api_clientimportApiClient,Configurationfromdatadog_api_client.v2.api.usage_metering_apiimportUsageMeteringApiconfiguration=Configuration()withApiClient(configuration)asapi_client:api_instance=UsageMeteringApi(api_client)response=api_instance.get_cost_by_org(start_month=(datetime.now()+relativedelta(days=-3)),)print(response)
# Get cost across multi-org account returns "OK" responserequire"datadog_api_client"api_instance=DatadogAPIClient::V2::UsageMeteringAPI.newpapi_instance.get_cost_by_org((Time.now+-3*86400))
// Get cost across multi-org account returns "OK" responsepackagemainimport("context""encoding/json""fmt""os""time""github.com/DataDog/datadog-api-client-go/v2/api/datadog""github.com/DataDog/datadog-api-client-go/v2/api/datadogV2")funcmain(){ctx:=datadog.NewDefaultContext(context.Background())configuration:=datadog.NewConfiguration()apiClient:=datadog.NewAPIClient(configuration)api:=datadogV2.NewUsageMeteringApi(apiClient)resp,r,err:=api.GetCostByOrg(ctx,time.Now().AddDate(0,0,-3),*datadogV2.NewGetCostByOrgOptionalParameters())iferr!=nil{fmt.Fprintf(os.Stderr,"Error when calling `UsageMeteringApi.GetCostByOrg`: %v\n",err)fmt.Fprintf(os.Stderr,"Full HTTP response: %v\n",r)}responseContent,_:=json.MarshalIndent(resp,""," ")fmt.Fprintf(os.Stdout,"Response from `UsageMeteringApi.GetCostByOrg`:\n%s\n",responseContent)}
// Get cost across multi-org account returns "OK" response
usechrono::{DateTime,Utc};usedatadog_api_client::datadog;usedatadog_api_client::datadogV2::api_usage_metering::GetCostByOrgOptionalParams;usedatadog_api_client::datadogV2::api_usage_metering::UsageMeteringAPI;#[tokio::main]asyncfnmain(){letconfiguration=datadog::Configuration::new();letapi=UsageMeteringAPI::with_config(configuration);letresp=api.get_cost_by_org(DateTime::parse_from_rfc3339("2021-11-08T11:11:11+00:00").expect("Failed to parse datetime").with_timezone(&Utc),GetCostByOrgOptionalParams::default(),).await;ifletOk(value)=resp{println!("{:#?}",value);}else{println!("{:#?}",resp.unwrap_err());}}
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 cost across multi-org account returns "OK" response
*/import{client,v2}from"@datadog/datadog-api-client";constconfiguration=client.createConfiguration();constapiInstance=newv2.UsageMeteringApi(configuration);constparams: v2.UsageMeteringApiGetCostByOrgRequest={startMonth: newDate(newDate().getTime()+-3*86400*1000),};apiInstance.getCostByOrg(params).then((data: v2.CostByOrgResponse)=>{console.log("API called successfully. Returned data: "+JSON.stringify(data));}).catch((error: any)=>console.error(error));