Create or replace a budget's custom forecast
https://api.datadoghq.com/api/v2/cost/budget/custom-forecasthttps://api.us3.datadoghq.com/api/v2/cost/budget/custom-forecasthttps://api.us5.datadoghq.com/api/v2/cost/budget/custom-forecasthttps://api.datadoghq.eu/api/v2/cost/budget/custom-forecasthttps://api.ap1.datadoghq.com/api/v2/cost/budget/custom-forecasthttps://api.ap2.datadoghq.com/api/v2/cost/budget/custom-forecasthttps://api.uk1.datadoghq.com/api/v2/cost/budget/custom-forecasthttps://api.ddog-gov.com/api/v2/cost/budget/custom-forecasthttps://api.us2.ddog-gov.com/api/v2/cost/budget/custom-forecast概要
Create or replace the custom forecast for an existing budget.
Pass an empty entries list to delete the custom forecast for the budget.
リクエスト
Body Data (required)
data [required]Custom forecast resource wrapper in an upsert request.
attributes [required]Attributes of a custom forecast upsert request.
budget_uid [required]The UUID of the budget that this custom forecast belongs to.
entries [required]Monthly custom forecast entries. An empty list deletes any existing custom forecast for the budget.
amount [required]Forecast amount for the month.
month [required]Month the custom forecast entry applies to, in YYYYMM format.
tag_filters [required]Tag filters that scope this custom forecast entry to specific resources.
tag_key [required]The tag key to filter on.
tag_value [required]The tag value to filter on.
idUnused on upsert; the resource is keyed by budget_uid. Send an empty string.
type [required]The type of the custom forecast resource. Must be custom_forecast.
custom_forecastcustom_forecast{
"data": {
"attributes": {
"budget_uid": "00000000-0000-0000-0000-000000000001",
"entries": [
{
"amount": 400,
"month": 202501,
"tag_filters": [
{
"tag_key": "service",
"tag_value": "ec2"
}
]
}
]
},
"id": "",
"type": "custom_forecast"
}
}応答
OK
Response object containing the custom forecast for a budget.
data [required]Custom forecast resource wrapper in a response.
attributes [required]Attributes of a custom forecast.
budget_uid [required]The UUID of the budget that this custom forecast belongs to.
created_at [required]Timestamp the custom forecast was created, in Unix milliseconds.
created_by [required]The id of the user that created the custom forecast.
entries [required]Monthly custom forecast entries.
amount [required]Forecast amount for the month.
month [required]Month the custom forecast entry applies to, in YYYYMM format.
tag_filters [required]Tag filters that scope this custom forecast entry to specific resources.
tag_key [required]The tag key to filter on.
tag_value [required]The tag value to filter on.
updated_at [required]Timestamp the custom forecast was last updated, in Unix milliseconds.
updated_by [required]The id of the user that last updated the custom forecast.
id [required]The unique identifier of the custom forecast.
type [required]The type of the custom forecast resource. Must be custom_forecast.
custom_forecastcustom_forecast{
"data": {
"attributes": {
"budget_uid": "00000000-0000-0000-0000-000000000001",
"created_at": 1738258683590,
"created_by": "00000000-0a0a-0a0a-aaa0-00000000000a",
"entries": [
{
"amount": 400,
"month": 202501,
"tag_filters": [
{
"tag_key": "service",
"tag_value": "ec2"
}
]
}
],
"updated_at": 1738258683590,
"updated_by": "00000000-0a0a-0a0a-aaa0-00000000000a"
},
"id": "11111111-1111-1111-1111-111111111111",
"type": "custom_forecast"
}
}Bad Request
API error response.
errors [required]A list of errors.
{
"errors": [
"Bad Request"
]
}Not Found
API error response.
errors [required]A list of errors.
{
"errors": [
"Bad Request"
]
}Too many requests
API error response.
errors [required]A list of errors.
{
"errors": [
"Bad Request"
]
}コード例
# Set your Datadog site and credentials
export DD_SITE="datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X PUT "https://api.${DD_SITE}/api/v2/cost/budget/custom-forecast" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"budget_uid": "00000000-0000-0000-0000-000000000001",
"entries": [
{
"amount": 400,
"month": 202501,
"tag_filters": [
{
"tag_key": "service",
"tag_value": "ec2"
}
]
},
{
"amount": 450,
"month": 202502,
"tag_filters": [
{
"tag_key": "service",
"tag_value": "ec2"
}
]
}
]
},
"id": "",
"type": "custom_forecast"
}
}
EOF# Set your Datadog site and credentials
export DD_SITE="us3.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X PUT "https://api.${DD_SITE}/api/v2/cost/budget/custom-forecast" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"budget_uid": "00000000-0000-0000-0000-000000000001",
"entries": [
{
"amount": 400,
"month": 202501,
"tag_filters": [
{
"tag_key": "service",
"tag_value": "ec2"
}
]
},
{
"amount": 450,
"month": 202502,
"tag_filters": [
{
"tag_key": "service",
"tag_value": "ec2"
}
]
}
]
},
"id": "",
"type": "custom_forecast"
}
}
EOF# Set your Datadog site and credentials
export DD_SITE="us5.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X PUT "https://api.${DD_SITE}/api/v2/cost/budget/custom-forecast" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"budget_uid": "00000000-0000-0000-0000-000000000001",
"entries": [
{
"amount": 400,
"month": 202501,
"tag_filters": [
{
"tag_key": "service",
"tag_value": "ec2"
}
]
},
{
"amount": 450,
"month": 202502,
"tag_filters": [
{
"tag_key": "service",
"tag_value": "ec2"
}
]
}
]
},
"id": "",
"type": "custom_forecast"
}
}
EOF# Set your Datadog site and credentials
export DD_SITE="datadoghq.eu"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X PUT "https://api.${DD_SITE}/api/v2/cost/budget/custom-forecast" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"budget_uid": "00000000-0000-0000-0000-000000000001",
"entries": [
{
"amount": 400,
"month": 202501,
"tag_filters": [
{
"tag_key": "service",
"tag_value": "ec2"
}
]
},
{
"amount": 450,
"month": 202502,
"tag_filters": [
{
"tag_key": "service",
"tag_value": "ec2"
}
]
}
]
},
"id": "",
"type": "custom_forecast"
}
}
EOF# Set your Datadog site and credentials
export DD_SITE="ap1.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X PUT "https://api.${DD_SITE}/api/v2/cost/budget/custom-forecast" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"budget_uid": "00000000-0000-0000-0000-000000000001",
"entries": [
{
"amount": 400,
"month": 202501,
"tag_filters": [
{
"tag_key": "service",
"tag_value": "ec2"
}
]
},
{
"amount": 450,
"month": 202502,
"tag_filters": [
{
"tag_key": "service",
"tag_value": "ec2"
}
]
}
]
},
"id": "",
"type": "custom_forecast"
}
}
EOF# Set your Datadog site and credentials
export DD_SITE="ap2.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X PUT "https://api.${DD_SITE}/api/v2/cost/budget/custom-forecast" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"budget_uid": "00000000-0000-0000-0000-000000000001",
"entries": [
{
"amount": 400,
"month": 202501,
"tag_filters": [
{
"tag_key": "service",
"tag_value": "ec2"
}
]
},
{
"amount": 450,
"month": 202502,
"tag_filters": [
{
"tag_key": "service",
"tag_value": "ec2"
}
]
}
]
},
"id": "",
"type": "custom_forecast"
}
}
EOF# Set your Datadog site and credentials
export DD_SITE="uk1.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X PUT "https://api.${DD_SITE}/api/v2/cost/budget/custom-forecast" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"budget_uid": "00000000-0000-0000-0000-000000000001",
"entries": [
{
"amount": 400,
"month": 202501,
"tag_filters": [
{
"tag_key": "service",
"tag_value": "ec2"
}
]
},
{
"amount": 450,
"month": 202502,
"tag_filters": [
{
"tag_key": "service",
"tag_value": "ec2"
}
]
}
]
},
"id": "",
"type": "custom_forecast"
}
}
EOF# Set your Datadog site and credentials
export DD_SITE="ddog-gov.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X PUT "https://api.${DD_SITE}/api/v2/cost/budget/custom-forecast" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"budget_uid": "00000000-0000-0000-0000-000000000001",
"entries": [
{
"amount": 400,
"month": 202501,
"tag_filters": [
{
"tag_key": "service",
"tag_value": "ec2"
}
]
},
{
"amount": 450,
"month": 202502,
"tag_filters": [
{
"tag_key": "service",
"tag_value": "ec2"
}
]
}
]
},
"id": "",
"type": "custom_forecast"
}
}
EOF# Set your Datadog site and credentials
export DD_SITE="us2.ddog-gov.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X PUT "https://api.${DD_SITE}/api/v2/cost/budget/custom-forecast" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"budget_uid": "00000000-0000-0000-0000-000000000001",
"entries": [
{
"amount": 400,
"month": 202501,
"tag_filters": [
{
"tag_key": "service",
"tag_value": "ec2"
}
]
},
{
"amount": 450,
"month": 202502,
"tag_filters": [
{
"tag_key": "service",
"tag_value": "ec2"
}
]
}
]
},
"id": "",
"type": "custom_forecast"
}
}
EOF// Create or replace a budget's custom forecast 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.CustomForecastUpsertRequest{
Data: datadogV2.CustomForecastUpsertRequestData{
Attributes: datadogV2.CustomForecastUpsertRequestDataAttributes{
BudgetUid: "00000000-0000-0000-0000-000000000001",
Entries: []datadogV2.CustomForecastEntry{
{
Amount: 400,
Month: 202501,
TagFilters: []datadogV2.CustomForecastEntryTagFilter{
{
TagKey: "service",
TagValue: "ec2",
},
},
},
},
},
Id: datadog.PtrString(""),
Type: datadogV2.CUSTOMFORECASTTYPE_CUSTOM_FORECAST,
},
}
ctx := datadog.NewDefaultContext(context.Background())
ctx = context.WithValue(ctx, datadog.ContextAccessToken, os.Getenv("DD_BEARER_TOKEN"))
configuration := datadog.NewConfiguration()
apiClient := datadog.NewAPIClient(configuration)
api := datadogV2.NewCloudCostManagementApi(apiClient)
resp, r, err := api.UpsertCustomForecast(ctx, body)
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `CloudCostManagementApi.UpsertCustomForecast`: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
responseContent, _ := json.MarshalIndent(resp, "", " ")
fmt.Fprintf(os.Stdout, "Response from `CloudCostManagementApi.UpsertCustomForecast`:\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.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"// Create or replace a budget's custom forecast 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.CustomForecastEntry;
import com.datadog.api.client.v2.model.CustomForecastEntryTagFilter;
import com.datadog.api.client.v2.model.CustomForecastResponse;
import com.datadog.api.client.v2.model.CustomForecastType;
import com.datadog.api.client.v2.model.CustomForecastUpsertRequest;
import com.datadog.api.client.v2.model.CustomForecastUpsertRequestData;
import com.datadog.api.client.v2.model.CustomForecastUpsertRequestDataAttributes;
import java.util.Collections;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = ApiClient.getDefaultApiClient();
defaultClient.setAccessToken(System.getenv("DD_BEARER_TOKEN"));
CloudCostManagementApi apiInstance = new CloudCostManagementApi(defaultClient);
CustomForecastUpsertRequest body =
new CustomForecastUpsertRequest()
.data(
new CustomForecastUpsertRequestData()
.attributes(
new CustomForecastUpsertRequestDataAttributes()
.budgetUid("00000000-0000-0000-0000-000000000001")
.entries(
Collections.singletonList(
new CustomForecastEntry()
.amount(400.0)
.month(202501L)
.tagFilters(
Collections.singletonList(
new CustomForecastEntryTagFilter()
.tagKey("service")
.tagValue("ec2"))))))
.id("")
.type(CustomForecastType.CUSTOM_FORECAST));
try {
CustomForecastResponse result = apiInstance.upsertCustomForecast(body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling CloudCostManagementApi#upsertCustomForecast");
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.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java""""
Create or replace a budget's custom forecast returns "OK" response
"""
from os import environ
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.custom_forecast_entry import CustomForecastEntry
from datadog_api_client.v2.model.custom_forecast_entry_tag_filter import CustomForecastEntryTagFilter
from datadog_api_client.v2.model.custom_forecast_type import CustomForecastType
from datadog_api_client.v2.model.custom_forecast_upsert_request import CustomForecastUpsertRequest
from datadog_api_client.v2.model.custom_forecast_upsert_request_data import CustomForecastUpsertRequestData
from datadog_api_client.v2.model.custom_forecast_upsert_request_data_attributes import (
CustomForecastUpsertRequestDataAttributes,
)
body = CustomForecastUpsertRequest(
data=CustomForecastUpsertRequestData(
attributes=CustomForecastUpsertRequestDataAttributes(
budget_uid="00000000-0000-0000-0000-000000000001",
entries=[
CustomForecastEntry(
amount=400.0,
month=202501,
tag_filters=[
CustomForecastEntryTagFilter(
tag_key="service",
tag_value="ec2",
),
],
),
],
),
id="",
type=CustomForecastType.CUSTOM_FORECAST,
),
)
configuration = Configuration()
configuration.access_token = environ["DD_BEARER_TOKEN"]
with ApiClient(configuration) as api_client:
api_instance = CloudCostManagementApi(api_client)
response = api_instance.upsert_custom_forecast(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.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"# Create or replace a budget's custom forecast returns "OK" response
require "datadog_api_client"
DatadogAPIClient.configure do |config|
config.access_token = ENV["DD_BEARER_TOKEN"]
end
api_instance = DatadogAPIClient::V2::CloudCostManagementAPI.new
body = DatadogAPIClient::V2::CustomForecastUpsertRequest.new({
data: DatadogAPIClient::V2::CustomForecastUpsertRequestData.new({
attributes: DatadogAPIClient::V2::CustomForecastUpsertRequestDataAttributes.new({
budget_uid: "00000000-0000-0000-0000-000000000001",
entries: [
DatadogAPIClient::V2::CustomForecastEntry.new({
amount: 400,
month: 202501,
tag_filters: [
DatadogAPIClient::V2::CustomForecastEntryTagFilter.new({
tag_key: "service",
tag_value: "ec2",
}),
],
}),
],
}),
id: "",
type: DatadogAPIClient::V2::CustomForecastType::CUSTOM_FORECAST,
}),
})
p api_instance.upsert_custom_forecast(body)
Instructions
First install the library and its dependencies and then save the example to example.rb and run following commands:
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"// Create or replace a budget's custom forecast returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_cloud_cost_management::CloudCostManagementAPI;
use datadog_api_client::datadogV2::model::CustomForecastEntry;
use datadog_api_client::datadogV2::model::CustomForecastEntryTagFilter;
use datadog_api_client::datadogV2::model::CustomForecastType;
use datadog_api_client::datadogV2::model::CustomForecastUpsertRequest;
use datadog_api_client::datadogV2::model::CustomForecastUpsertRequestData;
use datadog_api_client::datadogV2::model::CustomForecastUpsertRequestDataAttributes;
#[tokio::main]
async fn main() {
let body = CustomForecastUpsertRequest::new(
CustomForecastUpsertRequestData::new(
CustomForecastUpsertRequestDataAttributes::new(
"00000000-0000-0000-0000-000000000001".to_string(),
vec![CustomForecastEntry::new(
400.0,
202501,
vec![CustomForecastEntryTagFilter::new(
"service".to_string(),
"ec2".to_string(),
)],
)],
),
CustomForecastType::CUSTOM_FORECAST,
)
.id("".to_string()),
);
let configuration = datadog::Configuration::new();
let api = CloudCostManagementAPI::with_config(configuration);
let resp = api.upsert_custom_forecast(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.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo runDD_SITE="us3.datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo runDD_SITE="us5.datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo runDD_SITE="datadoghq.eu" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo runDD_SITE="ap1.datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo runDD_SITE="ap2.datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo runDD_SITE="uk1.datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo runDD_SITE="ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo runDD_SITE="us2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo run/**
* Create or replace a budget's custom forecast returns "OK" response
*/
import { client, v2 } from "@datadog/datadog-api-client";
const configuration = client.createConfiguration({
authMethods: {
AuthZ: {
accessToken: process.env.DD_BEARER_TOKEN as string,
},
},
});
const apiInstance = new v2.CloudCostManagementApi(configuration);
const params: v2.CloudCostManagementApiUpsertCustomForecastRequest = {
body: {
data: {
attributes: {
budgetUid: "00000000-0000-0000-0000-000000000001",
entries: [
{
amount: 400,
month: 202501,
tagFilters: [
{
tagKey: "service",
tagValue: "ec2",
},
],
},
],
},
id: "",
type: "custom_forecast",
},
},
};
apiInstance
.upsertCustomForecast(params)
.then((data: v2.CustomForecastResponse) => {
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.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"