Enumera los cargos de previsión para el ámbito definido.
POST https://management.azure.com/{scope}/providers/Microsoft.CostManagement/forecast?api-version=2025-03-01
Con parámetros opcionales:
POST https://management.azure.com/{scope}/providers/Microsoft.CostManagement/forecast?api-version=2025-03-01&$filter={$filter}
Parámetros de identificador URI
| Nombre |
En |
Requerido |
Tipo |
Description |
|
scope
|
path |
True
|
string
|
Ámbito asociado a las operaciones de previsión. Esto incluye '/subscriptions/{subscriptionId}/' para el ámbito de la suscripción, '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' para el ámbito resourceGroup, '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' para el ámbito de la cuenta de facturación y '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' para el ámbito del departamento, '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{ enrollmentAccountId}' para el ámbito EnrollmentAccount, '/providers/Microsoft.Management/managementGroups/{managementGroupId} para el ámbito del grupo de administración, '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' para el ámbito billingProfile, '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}/invoiceSections/{invoiceSectionId}' para el ámbito invoiceSection y '/providers/Microsoft. Billing/billingAccounts/{billingAccountId}/customers/{customerId}' específico para los partners.
|
|
api-version
|
query |
True
|
string
minLength: 1
|
Versión de la API que se va a usar para esta operación.
|
|
$filter
|
query |
|
string
|
Puede usarse para filtrar las previsiones por propiedades/usageDate (hora Utc), properties/chargeType o properties/grain. El filtro admite 'eq', 'lt', 'gt', 'le', 'ge' y 'and'. Actualmente no admite 'ne', 'or' o 'not'.
|
Cuerpo de la solicitud
| Nombre |
Requerido |
Tipo |
Description |
|
dataset
|
True
|
ForecastDataset
|
Tiene definición para los datos de esta previsión.
|
|
timeframe
|
True
|
ForecastTimeframe
|
Período de tiempo para extraer datos para la previsión. Si es personalizado, se debe proporcionar un período de tiempo específico.
|
|
type
|
True
|
ForecastType
|
Tipo de la previsión.
|
|
includeActualCost
|
|
boolean
|
Valor booleano que determina si se incluirá realCost.
|
|
includeFreshPartialCost
|
|
boolean
|
Valor booleano que determina si FreshPartialCost se incluirá.
|
|
timePeriod
|
|
ForecastTimePeriod
|
Tiene un período de tiempo para extraer datos para la previsión.
|
Respuestas
| Nombre |
Tipo |
Description |
|
200 OK
|
ForecastResult
|
La operación de Azure se completó correctamente.
|
|
204 No Content
|
|
No hay contenido que enviar para esta solicitud, pero los encabezados pueden ser útiles.
|
|
Other Status Codes
|
ErrorResponse
|
Una respuesta de error inesperada.
|
Seguridad
azure_auth
Flujo de OAuth2 de Azure Active Directory.
Tipo:
oauth2
Flujo:
implicit
Dirección URL de autorización:
https://login.microsoftonline.com/common/oauth2/authorize
Ámbitos
| Nombre |
Description |
|
user_impersonation
|
suplantar la cuenta de usuario
|
Ejemplos
BillingAccountForecast
Solicitud de ejemplo
POST https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/providers/Microsoft.CostManagement/forecast?api-version=2025-03-01
{
"type": "Usage",
"dataset": {
"aggregation": {
"totalCost": {
"name": "Cost",
"function": "Sum"
}
},
"filter": {
"and": [
{
"or": [
{
"dimensions": {
"name": "ResourceLocation",
"operator": "In",
"values": [
"East US",
"West Europe"
]
}
},
{
"tags": {
"name": "Environment",
"operator": "In",
"values": [
"UAT",
"Prod"
]
}
}
]
},
{
"dimensions": {
"name": "ResourceGroup",
"operator": "In",
"values": [
"API"
]
}
}
]
},
"granularity": "Daily"
},
"includeActualCost": false,
"includeFreshPartialCost": false,
"timePeriod": {
"from": "2022-08-01T00:00:00+00:00",
"to": "2022-08-31T23:59:59+00:00"
},
"timeframe": "Custom"
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.costmanagement import CostManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-costmanagement
# USAGE
python billing_account_forecast.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = CostManagementClient(
credential=DefaultAzureCredential(),
)
response = client.forecast.usage(
scope="providers/Microsoft.Billing/billingAccounts/12345:6789",
parameters={
"dataset": {
"aggregation": {"totalCost": {"function": "Sum", "name": "Cost"}},
"filter": {
"and": [
{
"or": [
{
"dimensions": {
"name": "ResourceLocation",
"operator": "In",
"values": ["East US", "West Europe"],
}
},
{"tags": {"name": "Environment", "operator": "In", "values": ["UAT", "Prod"]}},
]
},
{"dimensions": {"name": "ResourceGroup", "operator": "In", "values": ["API"]}},
]
},
"granularity": "Daily",
},
"includeActualCost": False,
"includeFreshPartialCost": False,
"timePeriod": {"from": "2022-08-01T00:00:00+00:00", "to": "2022-08-31T23:59:59+00:00"},
"timeframe": "Custom",
"type": "Usage",
},
)
print(response)
# x-ms-original-file: 2025-03-01/BillingAccountForecast.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcostmanagement_test
import (
"context"
"log"
"time"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/costmanagement/armcostmanagement/v3"
)
// Generated from example definition: 2025-03-01/BillingAccountForecast.json
func ExampleForecastClient_Usage_billingAccountForecast() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcostmanagement.NewClientFactory(cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewForecastClient().Usage(ctx, "providers/Microsoft.Billing/billingAccounts/12345:6789", armcostmanagement.ForecastDefinition{
Type: to.Ptr(armcostmanagement.ForecastTypeUsage),
Dataset: &armcostmanagement.ForecastDataset{
Aggregation: map[string]*armcostmanagement.ForecastAggregation{
"totalCost": {
Name: to.Ptr(armcostmanagement.FunctionNameCost),
Function: to.Ptr(armcostmanagement.FunctionTypeSum),
},
},
Filter: &armcostmanagement.ForecastFilter{
And: []*armcostmanagement.ForecastFilter{
{
Or: []*armcostmanagement.ForecastFilter{
{
Dimensions: &armcostmanagement.ForecastComparisonExpression{
Name: to.Ptr("ResourceLocation"),
Operator: to.Ptr(armcostmanagement.ForecastOperatorTypeIn),
Values: []*string{
to.Ptr("East US"),
to.Ptr("West Europe"),
},
},
},
{
Tags: &armcostmanagement.ForecastComparisonExpression{
Name: to.Ptr("Environment"),
Operator: to.Ptr(armcostmanagement.ForecastOperatorTypeIn),
Values: []*string{
to.Ptr("UAT"),
to.Ptr("Prod"),
},
},
},
},
},
{
Dimensions: &armcostmanagement.ForecastComparisonExpression{
Name: to.Ptr("ResourceGroup"),
Operator: to.Ptr(armcostmanagement.ForecastOperatorTypeIn),
Values: []*string{
to.Ptr("API"),
},
},
},
},
},
Granularity: to.Ptr(armcostmanagement.GranularityTypeDaily),
},
IncludeActualCost: to.Ptr(false),
IncludeFreshPartialCost: to.Ptr(false),
TimePeriod: &armcostmanagement.ForecastTimePeriod{
From: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-01T00:00:00+00:00"); return t }()),
To: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-31T23:59:59+00:00"); return t }()),
},
Timeframe: to.Ptr(armcostmanagement.ForecastTimeframeCustom),
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcostmanagement.ForecastClientUsageResponse{
// ForecastResult: armcostmanagement.ForecastResult{
// Name: to.Ptr("ad67fd91-c131-4bda-9ba9-7187ecb1cebd"),
// Type: to.Ptr("Microsoft.CostManagement/query"),
// ID: to.Ptr("/providers/Microsoft.Billing/billingAccounts/12345:6789/providers/Microsoft.CostManagement/query/ad67fd91-c131-4bda-9ba9-7187ecb1cebd"),
// Properties: &armcostmanagement.ForecastProperties{
// Columns: []*armcostmanagement.ForecastColumn{
// {
// Name: to.Ptr("PreTaxCost"),
// Type: to.Ptr("Number"),
// },
// {
// Name: to.Ptr("UsageDate"),
// Type: to.Ptr("Number"),
// },
// {
// Name: to.Ptr("CostStatus"),
// Type: to.Ptr("String"),
// },
// {
// Name: to.Ptr("Currency"),
// Type: to.Ptr("String"),
// },
// },
// NextLink: to.Ptr("https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/providers/Microsoft.CostManagement/Forecast?api-version=2021-10-01&$skiptoken=AQAAAA%3D%3D"),
// Rows: [][]any{
// []any{
// 2.10333307059661,
// 20180331,
// "Forecast",
// "USD",
// },
// []any{
// 218.68795741935486,
// 20180331,
// "Forecast",
// "USD",
// },
// []any{
// 0.14384913581657052,
// 20180401,
// "Forecast",
// "USD",
// },
// []any{
// 0.009865586851323632,
// 20180429,
// "Forecast",
// "USD",
// },
// },
// },
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { CostManagementClient } = require("@azure/arm-costmanagement");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to lists the forecast charges for scope defined.
*
* @summary lists the forecast charges for scope defined.
* x-ms-original-file: 2025-03-01/BillingAccountForecast.json
*/
async function billingAccountForecast() {
const credential = new DefaultAzureCredential();
const client = new CostManagementClient(credential);
const result = await client.forecast.usage(
"providers/Microsoft.Billing/billingAccounts/12345:6789",
{
type: "Usage",
dataset: {
aggregation: { totalCost: { name: "Cost", function: "Sum" } },
filter: {
and: [
{
or: [
{
dimensions: {
name: "ResourceLocation",
operator: "In",
values: ["East US", "West Europe"],
},
},
{ tags: { name: "Environment", operator: "In", values: ["UAT", "Prod"] } },
],
},
{ dimensions: { name: "ResourceGroup", operator: "In", values: ["API"] } },
],
},
granularity: "Daily",
},
includeActualCost: false,
includeFreshPartialCost: false,
timePeriod: {
from: new Date("2022-08-01T00:00:00+00:00"),
to: new Date("2022-08-31T23:59:59+00:00"),
},
timeframe: "Custom",
},
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Respuesta de muestra
{
"name": "ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"type": "Microsoft.CostManagement/query",
"id": "/providers/Microsoft.Billing/billingAccounts/12345:6789/providers/Microsoft.CostManagement/query/ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"properties": {
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "UsageDate",
"type": "Number"
},
{
"name": "CostStatus",
"type": "String"
},
{
"name": "Currency",
"type": "String"
}
],
"nextLink": "https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/providers/Microsoft.CostManagement/Forecast?api-version=2021-10-01&$skiptoken=AQAAAA%3D%3D",
"rows": [
[
2.10333307059661,
20180331,
"Forecast",
"USD"
],
[
218.68795741935486,
20180331,
"Forecast",
"USD"
],
[
0.14384913581657052,
20180401,
"Forecast",
"USD"
],
[
0.009865586851323632,
20180429,
"Forecast",
"USD"
]
]
}
}
BillingProfileForecast
Solicitud de ejemplo
POST https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/billingProfiles/13579/providers/Microsoft.CostManagement/forecast?api-version=2025-03-01
{
"type": "Usage",
"dataset": {
"aggregation": {
"totalCost": {
"name": "Cost",
"function": "Sum"
}
},
"filter": {
"and": [
{
"or": [
{
"dimensions": {
"name": "ResourceLocation",
"operator": "In",
"values": [
"East US",
"West Europe"
]
}
},
{
"tags": {
"name": "Environment",
"operator": "In",
"values": [
"UAT",
"Prod"
]
}
}
]
},
{
"dimensions": {
"name": "ResourceGroup",
"operator": "In",
"values": [
"API"
]
}
}
]
},
"granularity": "Daily"
},
"includeActualCost": false,
"includeFreshPartialCost": false,
"timePeriod": {
"from": "2022-08-01T00:00:00+00:00",
"to": "2022-08-31T23:59:59+00:00"
},
"timeframe": "Custom"
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.costmanagement import CostManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-costmanagement
# USAGE
python billing_profile_forecast.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = CostManagementClient(
credential=DefaultAzureCredential(),
)
response = client.forecast.usage(
scope="providers/Microsoft.Billing/billingAccounts/12345:6789/billingProfiles/13579",
parameters={
"dataset": {
"aggregation": {"totalCost": {"function": "Sum", "name": "Cost"}},
"filter": {
"and": [
{
"or": [
{
"dimensions": {
"name": "ResourceLocation",
"operator": "In",
"values": ["East US", "West Europe"],
}
},
{"tags": {"name": "Environment", "operator": "In", "values": ["UAT", "Prod"]}},
]
},
{"dimensions": {"name": "ResourceGroup", "operator": "In", "values": ["API"]}},
]
},
"granularity": "Daily",
},
"includeActualCost": False,
"includeFreshPartialCost": False,
"timePeriod": {"from": "2022-08-01T00:00:00+00:00", "to": "2022-08-31T23:59:59+00:00"},
"timeframe": "Custom",
"type": "Usage",
},
)
print(response)
# x-ms-original-file: 2025-03-01/BillingProfileForecast.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcostmanagement_test
import (
"context"
"log"
"time"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/costmanagement/armcostmanagement/v3"
)
// Generated from example definition: 2025-03-01/BillingProfileForecast.json
func ExampleForecastClient_Usage_billingProfileForecast() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcostmanagement.NewClientFactory(cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewForecastClient().Usage(ctx, "providers/Microsoft.Billing/billingAccounts/12345:6789/billingProfiles/13579", armcostmanagement.ForecastDefinition{
Type: to.Ptr(armcostmanagement.ForecastTypeUsage),
Dataset: &armcostmanagement.ForecastDataset{
Aggregation: map[string]*armcostmanagement.ForecastAggregation{
"totalCost": {
Name: to.Ptr(armcostmanagement.FunctionNameCost),
Function: to.Ptr(armcostmanagement.FunctionTypeSum),
},
},
Filter: &armcostmanagement.ForecastFilter{
And: []*armcostmanagement.ForecastFilter{
{
Or: []*armcostmanagement.ForecastFilter{
{
Dimensions: &armcostmanagement.ForecastComparisonExpression{
Name: to.Ptr("ResourceLocation"),
Operator: to.Ptr(armcostmanagement.ForecastOperatorTypeIn),
Values: []*string{
to.Ptr("East US"),
to.Ptr("West Europe"),
},
},
},
{
Tags: &armcostmanagement.ForecastComparisonExpression{
Name: to.Ptr("Environment"),
Operator: to.Ptr(armcostmanagement.ForecastOperatorTypeIn),
Values: []*string{
to.Ptr("UAT"),
to.Ptr("Prod"),
},
},
},
},
},
{
Dimensions: &armcostmanagement.ForecastComparisonExpression{
Name: to.Ptr("ResourceGroup"),
Operator: to.Ptr(armcostmanagement.ForecastOperatorTypeIn),
Values: []*string{
to.Ptr("API"),
},
},
},
},
},
Granularity: to.Ptr(armcostmanagement.GranularityTypeDaily),
},
IncludeActualCost: to.Ptr(false),
IncludeFreshPartialCost: to.Ptr(false),
TimePeriod: &armcostmanagement.ForecastTimePeriod{
From: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-01T00:00:00+00:00"); return t }()),
To: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-31T23:59:59+00:00"); return t }()),
},
Timeframe: to.Ptr(armcostmanagement.ForecastTimeframeCustom),
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcostmanagement.ForecastClientUsageResponse{
// ForecastResult: armcostmanagement.ForecastResult{
// Name: to.Ptr("ad67fd91-c131-4bda-9ba9-7187ecb1cebd"),
// Type: to.Ptr("Microsoft.CostManagement/query"),
// ID: to.Ptr("/providers/Microsoft.Billing/billingAccounts/12345:6789/billingProfiles/13579/providers/Microsoft.CostManagement/query/ad67fd91-c131-4bda-9ba9-7187ecb1cebd"),
// Properties: &armcostmanagement.ForecastProperties{
// Columns: []*armcostmanagement.ForecastColumn{
// {
// Name: to.Ptr("PreTaxCost"),
// Type: to.Ptr("Number"),
// },
// {
// Name: to.Ptr("UsageDate"),
// Type: to.Ptr("Number"),
// },
// {
// Name: to.Ptr("CostStatus"),
// Type: to.Ptr("String"),
// },
// {
// Name: to.Ptr("Currency"),
// Type: to.Ptr("String"),
// },
// },
// NextLink: to.Ptr("https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/billingProfiles/13579/providers/Microsoft.CostManagement/Forecast?api-version=2019-10-01&$skiptoken=AQAAAA%3D%3D"),
// Rows: [][]any{
// []any{
// 2.10333307059661,
// 20180331,
// "Forecast",
// "USD",
// },
// []any{
// 218.68795741935486,
// 20180331,
// "Forecast",
// "USD",
// },
// []any{
// 0.14384913581657052,
// 20180401,
// "Forecast",
// "USD",
// },
// []any{
// 0.009865586851323632,
// 20180429,
// "Forecast",
// "USD",
// },
// },
// },
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { CostManagementClient } = require("@azure/arm-costmanagement");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to lists the forecast charges for scope defined.
*
* @summary lists the forecast charges for scope defined.
* x-ms-original-file: 2025-03-01/BillingProfileForecast.json
*/
async function billingProfileForecast() {
const credential = new DefaultAzureCredential();
const client = new CostManagementClient(credential);
const result = await client.forecast.usage(
"providers/Microsoft.Billing/billingAccounts/12345:6789/billingProfiles/13579",
{
type: "Usage",
dataset: {
aggregation: { totalCost: { name: "Cost", function: "Sum" } },
filter: {
and: [
{
or: [
{
dimensions: {
name: "ResourceLocation",
operator: "In",
values: ["East US", "West Europe"],
},
},
{ tags: { name: "Environment", operator: "In", values: ["UAT", "Prod"] } },
],
},
{ dimensions: { name: "ResourceGroup", operator: "In", values: ["API"] } },
],
},
granularity: "Daily",
},
includeActualCost: false,
includeFreshPartialCost: false,
timePeriod: {
from: new Date("2022-08-01T00:00:00+00:00"),
to: new Date("2022-08-31T23:59:59+00:00"),
},
timeframe: "Custom",
},
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Respuesta de muestra
{
"name": "ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"type": "Microsoft.CostManagement/query",
"id": "/providers/Microsoft.Billing/billingAccounts/12345:6789/billingProfiles/13579/providers/Microsoft.CostManagement/query/ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"properties": {
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "UsageDate",
"type": "Number"
},
{
"name": "CostStatus",
"type": "String"
},
{
"name": "Currency",
"type": "String"
}
],
"nextLink": "https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/billingProfiles/13579/providers/Microsoft.CostManagement/Forecast?api-version=2019-10-01&$skiptoken=AQAAAA%3D%3D",
"rows": [
[
2.10333307059661,
20180331,
"Forecast",
"USD"
],
[
218.68795741935486,
20180331,
"Forecast",
"USD"
],
[
0.14384913581657052,
20180401,
"Forecast",
"USD"
],
[
0.009865586851323632,
20180429,
"Forecast",
"USD"
]
]
}
}
DepartmentForecast
Solicitud de ejemplo
POST https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/departments/123/providers/Microsoft.CostManagement/forecast?api-version=2025-03-01
{
"type": "Usage",
"dataset": {
"aggregation": {
"totalCost": {
"name": "Cost",
"function": "Sum"
}
},
"filter": {
"and": [
{
"or": [
{
"dimensions": {
"name": "ResourceLocation",
"operator": "In",
"values": [
"East US",
"West Europe"
]
}
},
{
"tags": {
"name": "Environment",
"operator": "In",
"values": [
"UAT",
"Prod"
]
}
}
]
},
{
"dimensions": {
"name": "ResourceGroup",
"operator": "In",
"values": [
"API"
]
}
}
]
},
"granularity": "Daily"
},
"includeActualCost": false,
"includeFreshPartialCost": false,
"timePeriod": {
"from": "2022-08-01T00:00:00+00:00",
"to": "2022-08-31T23:59:59+00:00"
},
"timeframe": "Custom"
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.costmanagement import CostManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-costmanagement
# USAGE
python department_forecast.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = CostManagementClient(
credential=DefaultAzureCredential(),
)
response = client.forecast.usage(
scope="providers/Microsoft.Billing/billingAccounts/12345:6789/departments/123",
parameters={
"dataset": {
"aggregation": {"totalCost": {"function": "Sum", "name": "Cost"}},
"filter": {
"and": [
{
"or": [
{
"dimensions": {
"name": "ResourceLocation",
"operator": "In",
"values": ["East US", "West Europe"],
}
},
{"tags": {"name": "Environment", "operator": "In", "values": ["UAT", "Prod"]}},
]
},
{"dimensions": {"name": "ResourceGroup", "operator": "In", "values": ["API"]}},
]
},
"granularity": "Daily",
},
"includeActualCost": False,
"includeFreshPartialCost": False,
"timePeriod": {"from": "2022-08-01T00:00:00+00:00", "to": "2022-08-31T23:59:59+00:00"},
"timeframe": "Custom",
"type": "Usage",
},
)
print(response)
# x-ms-original-file: 2025-03-01/DepartmentForecast.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcostmanagement_test
import (
"context"
"log"
"time"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/costmanagement/armcostmanagement/v3"
)
// Generated from example definition: 2025-03-01/DepartmentForecast.json
func ExampleForecastClient_Usage_departmentForecast() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcostmanagement.NewClientFactory(cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewForecastClient().Usage(ctx, "providers/Microsoft.Billing/billingAccounts/12345:6789/departments/123", armcostmanagement.ForecastDefinition{
Type: to.Ptr(armcostmanagement.ForecastTypeUsage),
Dataset: &armcostmanagement.ForecastDataset{
Aggregation: map[string]*armcostmanagement.ForecastAggregation{
"totalCost": {
Name: to.Ptr(armcostmanagement.FunctionNameCost),
Function: to.Ptr(armcostmanagement.FunctionTypeSum),
},
},
Filter: &armcostmanagement.ForecastFilter{
And: []*armcostmanagement.ForecastFilter{
{
Or: []*armcostmanagement.ForecastFilter{
{
Dimensions: &armcostmanagement.ForecastComparisonExpression{
Name: to.Ptr("ResourceLocation"),
Operator: to.Ptr(armcostmanagement.ForecastOperatorTypeIn),
Values: []*string{
to.Ptr("East US"),
to.Ptr("West Europe"),
},
},
},
{
Tags: &armcostmanagement.ForecastComparisonExpression{
Name: to.Ptr("Environment"),
Operator: to.Ptr(armcostmanagement.ForecastOperatorTypeIn),
Values: []*string{
to.Ptr("UAT"),
to.Ptr("Prod"),
},
},
},
},
},
{
Dimensions: &armcostmanagement.ForecastComparisonExpression{
Name: to.Ptr("ResourceGroup"),
Operator: to.Ptr(armcostmanagement.ForecastOperatorTypeIn),
Values: []*string{
to.Ptr("API"),
},
},
},
},
},
Granularity: to.Ptr(armcostmanagement.GranularityTypeDaily),
},
IncludeActualCost: to.Ptr(false),
IncludeFreshPartialCost: to.Ptr(false),
TimePeriod: &armcostmanagement.ForecastTimePeriod{
From: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-01T00:00:00+00:00"); return t }()),
To: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-31T23:59:59+00:00"); return t }()),
},
Timeframe: to.Ptr(armcostmanagement.ForecastTimeframeCustom),
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcostmanagement.ForecastClientUsageResponse{
// ForecastResult: armcostmanagement.ForecastResult{
// Name: to.Ptr("ad67fd91-c131-4bda-9ba9-7187ecb1cebd"),
// Type: to.Ptr("Microsoft.CostManagement/query"),
// ID: to.Ptr("/providers/Microsoft.Billing/billingAccounts/12345:6789/departments/123/providers/Microsoft.CostManagement/query/ad67fd91-c131-4bda-9ba9-7187ecb1cebd"),
// Properties: &armcostmanagement.ForecastProperties{
// Columns: []*armcostmanagement.ForecastColumn{
// {
// Name: to.Ptr("PreTaxCost"),
// Type: to.Ptr("Number"),
// },
// {
// Name: to.Ptr("UsageDate"),
// Type: to.Ptr("Number"),
// },
// {
// Name: to.Ptr("CostStatus"),
// Type: to.Ptr("String"),
// },
// {
// Name: to.Ptr("Currency"),
// Type: to.Ptr("String"),
// },
// },
// NextLink: to.Ptr("https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/departments/123/providers/Microsoft.CostManagement/Forecast?api-version=2021-10-01&$skiptoken=AQAAAA%3D%3D"),
// Rows: [][]any{
// []any{
// 2.10333307059661,
// 20180331,
// "Forecast",
// "USD",
// },
// []any{
// 218.68795741935486,
// 20180331,
// "Forecast",
// "USD",
// },
// []any{
// 0.14384913581657052,
// 20180401,
// "Forecast",
// "USD",
// },
// []any{
// 0.009865586851323632,
// 20180429,
// "Forecast",
// "USD",
// },
// },
// },
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { CostManagementClient } = require("@azure/arm-costmanagement");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to lists the forecast charges for scope defined.
*
* @summary lists the forecast charges for scope defined.
* x-ms-original-file: 2025-03-01/DepartmentForecast.json
*/
async function departmentForecast() {
const credential = new DefaultAzureCredential();
const client = new CostManagementClient(credential);
const result = await client.forecast.usage(
"providers/Microsoft.Billing/billingAccounts/12345:6789/departments/123",
{
type: "Usage",
dataset: {
aggregation: { totalCost: { name: "Cost", function: "Sum" } },
filter: {
and: [
{
or: [
{
dimensions: {
name: "ResourceLocation",
operator: "In",
values: ["East US", "West Europe"],
},
},
{ tags: { name: "Environment", operator: "In", values: ["UAT", "Prod"] } },
],
},
{ dimensions: { name: "ResourceGroup", operator: "In", values: ["API"] } },
],
},
granularity: "Daily",
},
includeActualCost: false,
includeFreshPartialCost: false,
timePeriod: {
from: new Date("2022-08-01T00:00:00+00:00"),
to: new Date("2022-08-31T23:59:59+00:00"),
},
timeframe: "Custom",
},
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Respuesta de muestra
{
"name": "ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"type": "Microsoft.CostManagement/query",
"id": "/providers/Microsoft.Billing/billingAccounts/12345:6789/departments/123/providers/Microsoft.CostManagement/query/ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"properties": {
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "UsageDate",
"type": "Number"
},
{
"name": "CostStatus",
"type": "String"
},
{
"name": "Currency",
"type": "String"
}
],
"nextLink": "https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/departments/123/providers/Microsoft.CostManagement/Forecast?api-version=2021-10-01&$skiptoken=AQAAAA%3D%3D",
"rows": [
[
2.10333307059661,
20180331,
"Forecast",
"USD"
],
[
218.68795741935486,
20180331,
"Forecast",
"USD"
],
[
0.14384913581657052,
20180401,
"Forecast",
"USD"
],
[
0.009865586851323632,
20180429,
"Forecast",
"USD"
]
]
}
}
EnrollmentAccountForecast
Solicitud de ejemplo
POST https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/enrollmentAccounts/456/providers/Microsoft.CostManagement/forecast?api-version=2025-03-01
{
"type": "Usage",
"dataset": {
"aggregation": {
"totalCost": {
"name": "Cost",
"function": "Sum"
}
},
"filter": {
"and": [
{
"or": [
{
"dimensions": {
"name": "ResourceLocation",
"operator": "In",
"values": [
"East US",
"West Europe"
]
}
},
{
"tags": {
"name": "Environment",
"operator": "In",
"values": [
"UAT",
"Prod"
]
}
}
]
},
{
"dimensions": {
"name": "ResourceGroup",
"operator": "In",
"values": [
"API"
]
}
}
]
},
"granularity": "Daily"
},
"includeActualCost": false,
"includeFreshPartialCost": false,
"timePeriod": {
"from": "2022-08-01T00:00:00+00:00",
"to": "2022-08-31T23:59:59+00:00"
},
"timeframe": "Custom"
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.costmanagement import CostManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-costmanagement
# USAGE
python enrollment_account_forecast.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = CostManagementClient(
credential=DefaultAzureCredential(),
)
response = client.forecast.usage(
scope="providers/Microsoft.Billing/billingAccounts/12345:6789/enrollmentAccounts/456",
parameters={
"dataset": {
"aggregation": {"totalCost": {"function": "Sum", "name": "Cost"}},
"filter": {
"and": [
{
"or": [
{
"dimensions": {
"name": "ResourceLocation",
"operator": "In",
"values": ["East US", "West Europe"],
}
},
{"tags": {"name": "Environment", "operator": "In", "values": ["UAT", "Prod"]}},
]
},
{"dimensions": {"name": "ResourceGroup", "operator": "In", "values": ["API"]}},
]
},
"granularity": "Daily",
},
"includeActualCost": False,
"includeFreshPartialCost": False,
"timePeriod": {"from": "2022-08-01T00:00:00+00:00", "to": "2022-08-31T23:59:59+00:00"},
"timeframe": "Custom",
"type": "Usage",
},
)
print(response)
# x-ms-original-file: 2025-03-01/EnrollmentAccountForecast.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcostmanagement_test
import (
"context"
"log"
"time"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/costmanagement/armcostmanagement/v3"
)
// Generated from example definition: 2025-03-01/EnrollmentAccountForecast.json
func ExampleForecastClient_Usage_enrollmentAccountForecast() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcostmanagement.NewClientFactory(cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewForecastClient().Usage(ctx, "providers/Microsoft.Billing/billingAccounts/12345:6789/enrollmentAccounts/456", armcostmanagement.ForecastDefinition{
Type: to.Ptr(armcostmanagement.ForecastTypeUsage),
Dataset: &armcostmanagement.ForecastDataset{
Aggregation: map[string]*armcostmanagement.ForecastAggregation{
"totalCost": {
Name: to.Ptr(armcostmanagement.FunctionNameCost),
Function: to.Ptr(armcostmanagement.FunctionTypeSum),
},
},
Filter: &armcostmanagement.ForecastFilter{
And: []*armcostmanagement.ForecastFilter{
{
Or: []*armcostmanagement.ForecastFilter{
{
Dimensions: &armcostmanagement.ForecastComparisonExpression{
Name: to.Ptr("ResourceLocation"),
Operator: to.Ptr(armcostmanagement.ForecastOperatorTypeIn),
Values: []*string{
to.Ptr("East US"),
to.Ptr("West Europe"),
},
},
},
{
Tags: &armcostmanagement.ForecastComparisonExpression{
Name: to.Ptr("Environment"),
Operator: to.Ptr(armcostmanagement.ForecastOperatorTypeIn),
Values: []*string{
to.Ptr("UAT"),
to.Ptr("Prod"),
},
},
},
},
},
{
Dimensions: &armcostmanagement.ForecastComparisonExpression{
Name: to.Ptr("ResourceGroup"),
Operator: to.Ptr(armcostmanagement.ForecastOperatorTypeIn),
Values: []*string{
to.Ptr("API"),
},
},
},
},
},
Granularity: to.Ptr(armcostmanagement.GranularityTypeDaily),
},
IncludeActualCost: to.Ptr(false),
IncludeFreshPartialCost: to.Ptr(false),
TimePeriod: &armcostmanagement.ForecastTimePeriod{
From: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-01T00:00:00+00:00"); return t }()),
To: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-31T23:59:59+00:00"); return t }()),
},
Timeframe: to.Ptr(armcostmanagement.ForecastTimeframeCustom),
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcostmanagement.ForecastClientUsageResponse{
// ForecastResult: armcostmanagement.ForecastResult{
// Name: to.Ptr("ad67fd91-c131-4bda-9ba9-7187ecb1cebd"),
// Type: to.Ptr("Microsoft.CostManagement/query"),
// ID: to.Ptr("/providers/Microsoft.Billing/billingAccounts/12345:6789/enrollmentAccounts/456/providers/Microsoft.CostManagement/query/ad67fd91-c131-4bda-9ba9-7187ecb1cebd"),
// Properties: &armcostmanagement.ForecastProperties{
// Columns: []*armcostmanagement.ForecastColumn{
// {
// Name: to.Ptr("PreTaxCost"),
// Type: to.Ptr("Number"),
// },
// {
// Name: to.Ptr("UsageDate"),
// Type: to.Ptr("Number"),
// },
// {
// Name: to.Ptr("CostStatus"),
// Type: to.Ptr("String"),
// },
// {
// Name: to.Ptr("Currency"),
// Type: to.Ptr("String"),
// },
// },
// NextLink: to.Ptr("https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/enrollmentAccounts/456/providers/Microsoft.CostManagement/Forecast?api-version=2021-10-01&$skiptoken=AQAAAA%3D%3D"),
// Rows: [][]any{
// []any{
// 2.10333307059661,
// 20180331,
// "Forecast",
// "USD",
// },
// []any{
// 218.68795741935486,
// 20180331,
// "Forecast",
// "USD",
// },
// []any{
// 0.14384913581657052,
// 20180401,
// "Forecast",
// "USD",
// },
// []any{
// 0.009865586851323632,
// 20180429,
// "Forecast",
// "USD",
// },
// },
// },
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { CostManagementClient } = require("@azure/arm-costmanagement");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to lists the forecast charges for scope defined.
*
* @summary lists the forecast charges for scope defined.
* x-ms-original-file: 2025-03-01/EnrollmentAccountForecast.json
*/
async function enrollmentAccountForecast() {
const credential = new DefaultAzureCredential();
const client = new CostManagementClient(credential);
const result = await client.forecast.usage(
"providers/Microsoft.Billing/billingAccounts/12345:6789/enrollmentAccounts/456",
{
type: "Usage",
dataset: {
aggregation: { totalCost: { name: "Cost", function: "Sum" } },
filter: {
and: [
{
or: [
{
dimensions: {
name: "ResourceLocation",
operator: "In",
values: ["East US", "West Europe"],
},
},
{ tags: { name: "Environment", operator: "In", values: ["UAT", "Prod"] } },
],
},
{ dimensions: { name: "ResourceGroup", operator: "In", values: ["API"] } },
],
},
granularity: "Daily",
},
includeActualCost: false,
includeFreshPartialCost: false,
timePeriod: {
from: new Date("2022-08-01T00:00:00+00:00"),
to: new Date("2022-08-31T23:59:59+00:00"),
},
timeframe: "Custom",
},
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Respuesta de muestra
{
"name": "ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"type": "Microsoft.CostManagement/query",
"id": "/providers/Microsoft.Billing/billingAccounts/12345:6789/enrollmentAccounts/456/providers/Microsoft.CostManagement/query/ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"properties": {
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "UsageDate",
"type": "Number"
},
{
"name": "CostStatus",
"type": "String"
},
{
"name": "Currency",
"type": "String"
}
],
"nextLink": "https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/enrollmentAccounts/456/providers/Microsoft.CostManagement/Forecast?api-version=2021-10-01&$skiptoken=AQAAAA%3D%3D",
"rows": [
[
2.10333307059661,
20180331,
"Forecast",
"USD"
],
[
218.68795741935486,
20180331,
"Forecast",
"USD"
],
[
0.14384913581657052,
20180401,
"Forecast",
"USD"
],
[
0.009865586851323632,
20180429,
"Forecast",
"USD"
]
]
}
}
InvoiceSectionForecast
Solicitud de ejemplo
POST https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/billingProfiles/13579/invoiceSections/9876/providers/Microsoft.CostManagement/forecast?api-version=2025-03-01
{
"type": "Usage",
"dataset": {
"aggregation": {
"totalCost": {
"name": "Cost",
"function": "Sum"
}
},
"filter": {
"and": [
{
"or": [
{
"dimensions": {
"name": "ResourceLocation",
"operator": "In",
"values": [
"East US",
"West Europe"
]
}
},
{
"tags": {
"name": "Environment",
"operator": "In",
"values": [
"UAT",
"Prod"
]
}
}
]
},
{
"dimensions": {
"name": "ResourceGroup",
"operator": "In",
"values": [
"API"
]
}
}
]
},
"granularity": "Daily"
},
"includeActualCost": false,
"includeFreshPartialCost": false,
"timePeriod": {
"from": "2022-08-01T00:00:00+00:00",
"to": "2022-08-31T23:59:59+00:00"
},
"timeframe": "Custom"
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.costmanagement import CostManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-costmanagement
# USAGE
python invoice_section_forecast.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = CostManagementClient(
credential=DefaultAzureCredential(),
)
response = client.forecast.usage(
scope="providers/Microsoft.Billing/billingAccounts/12345:6789/billingProfiles/13579/invoiceSections/9876",
parameters={
"dataset": {
"aggregation": {"totalCost": {"function": "Sum", "name": "Cost"}},
"filter": {
"and": [
{
"or": [
{
"dimensions": {
"name": "ResourceLocation",
"operator": "In",
"values": ["East US", "West Europe"],
}
},
{"tags": {"name": "Environment", "operator": "In", "values": ["UAT", "Prod"]}},
]
},
{"dimensions": {"name": "ResourceGroup", "operator": "In", "values": ["API"]}},
]
},
"granularity": "Daily",
},
"includeActualCost": False,
"includeFreshPartialCost": False,
"timePeriod": {"from": "2022-08-01T00:00:00+00:00", "to": "2022-08-31T23:59:59+00:00"},
"timeframe": "Custom",
"type": "Usage",
},
)
print(response)
# x-ms-original-file: 2025-03-01/InvoiceSectionForecast.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcostmanagement_test
import (
"context"
"log"
"time"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/costmanagement/armcostmanagement/v3"
)
// Generated from example definition: 2025-03-01/InvoiceSectionForecast.json
func ExampleForecastClient_Usage_invoiceSectionForecast() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcostmanagement.NewClientFactory(cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewForecastClient().Usage(ctx, "providers/Microsoft.Billing/billingAccounts/12345:6789/billingProfiles/13579/invoiceSections/9876", armcostmanagement.ForecastDefinition{
Type: to.Ptr(armcostmanagement.ForecastTypeUsage),
Dataset: &armcostmanagement.ForecastDataset{
Aggregation: map[string]*armcostmanagement.ForecastAggregation{
"totalCost": {
Name: to.Ptr(armcostmanagement.FunctionNameCost),
Function: to.Ptr(armcostmanagement.FunctionTypeSum),
},
},
Filter: &armcostmanagement.ForecastFilter{
And: []*armcostmanagement.ForecastFilter{
{
Or: []*armcostmanagement.ForecastFilter{
{
Dimensions: &armcostmanagement.ForecastComparisonExpression{
Name: to.Ptr("ResourceLocation"),
Operator: to.Ptr(armcostmanagement.ForecastOperatorTypeIn),
Values: []*string{
to.Ptr("East US"),
to.Ptr("West Europe"),
},
},
},
{
Tags: &armcostmanagement.ForecastComparisonExpression{
Name: to.Ptr("Environment"),
Operator: to.Ptr(armcostmanagement.ForecastOperatorTypeIn),
Values: []*string{
to.Ptr("UAT"),
to.Ptr("Prod"),
},
},
},
},
},
{
Dimensions: &armcostmanagement.ForecastComparisonExpression{
Name: to.Ptr("ResourceGroup"),
Operator: to.Ptr(armcostmanagement.ForecastOperatorTypeIn),
Values: []*string{
to.Ptr("API"),
},
},
},
},
},
Granularity: to.Ptr(armcostmanagement.GranularityTypeDaily),
},
IncludeActualCost: to.Ptr(false),
IncludeFreshPartialCost: to.Ptr(false),
TimePeriod: &armcostmanagement.ForecastTimePeriod{
From: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-01T00:00:00+00:00"); return t }()),
To: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-31T23:59:59+00:00"); return t }()),
},
Timeframe: to.Ptr(armcostmanagement.ForecastTimeframeCustom),
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcostmanagement.ForecastClientUsageResponse{
// ForecastResult: armcostmanagement.ForecastResult{
// Name: to.Ptr("ad67fd91-c131-4bda-9ba9-7187ecb1cebd"),
// Type: to.Ptr("Microsoft.CostManagement/query"),
// ID: to.Ptr("/providers/Microsoft.Billing/billingAccounts/12345:6789/billingProfiles/13579/invoiceSections/9876/providers/Microsoft.CostManagement/query/ad67fd91-c131-4bda-9ba9-7187ecb1cebd"),
// Properties: &armcostmanagement.ForecastProperties{
// Columns: []*armcostmanagement.ForecastColumn{
// {
// Name: to.Ptr("PreTaxCost"),
// Type: to.Ptr("Number"),
// },
// {
// Name: to.Ptr("UsageDate"),
// Type: to.Ptr("Number"),
// },
// {
// Name: to.Ptr("CostStatus"),
// Type: to.Ptr("String"),
// },
// {
// Name: to.Ptr("Currency"),
// Type: to.Ptr("String"),
// },
// },
// NextLink: to.Ptr("https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/billingProfiles/13579/invoiceSections/9876/providers/Microsoft.CostManagement/Forecast?api-version=2019-10-01&$skiptoken=AQAAAA%3D%3D"),
// Rows: [][]any{
// []any{
// 2.10333307059661,
// 20180331,
// "Forecast",
// "USD",
// },
// []any{
// 218.68795741935486,
// 20180331,
// "Forecast",
// "USD",
// },
// []any{
// 0.14384913581657052,
// 20180401,
// "Forecast",
// "USD",
// },
// []any{
// 0.009865586851323632,
// 20180429,
// "Forecast",
// "USD",
// },
// },
// },
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { CostManagementClient } = require("@azure/arm-costmanagement");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to lists the forecast charges for scope defined.
*
* @summary lists the forecast charges for scope defined.
* x-ms-original-file: 2025-03-01/InvoiceSectionForecast.json
*/
async function invoiceSectionForecast() {
const credential = new DefaultAzureCredential();
const client = new CostManagementClient(credential);
const result = await client.forecast.usage(
"providers/Microsoft.Billing/billingAccounts/12345:6789/billingProfiles/13579/invoiceSections/9876",
{
type: "Usage",
dataset: {
aggregation: { totalCost: { name: "Cost", function: "Sum" } },
filter: {
and: [
{
or: [
{
dimensions: {
name: "ResourceLocation",
operator: "In",
values: ["East US", "West Europe"],
},
},
{ tags: { name: "Environment", operator: "In", values: ["UAT", "Prod"] } },
],
},
{ dimensions: { name: "ResourceGroup", operator: "In", values: ["API"] } },
],
},
granularity: "Daily",
},
includeActualCost: false,
includeFreshPartialCost: false,
timePeriod: {
from: new Date("2022-08-01T00:00:00+00:00"),
to: new Date("2022-08-31T23:59:59+00:00"),
},
timeframe: "Custom",
},
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Respuesta de muestra
{
"name": "ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"type": "Microsoft.CostManagement/query",
"id": "/providers/Microsoft.Billing/billingAccounts/12345:6789/billingProfiles/13579/invoiceSections/9876/providers/Microsoft.CostManagement/query/ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"properties": {
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "UsageDate",
"type": "Number"
},
{
"name": "CostStatus",
"type": "String"
},
{
"name": "Currency",
"type": "String"
}
],
"nextLink": "https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/billingProfiles/13579/invoiceSections/9876/providers/Microsoft.CostManagement/Forecast?api-version=2019-10-01&$skiptoken=AQAAAA%3D%3D",
"rows": [
[
2.10333307059661,
20180331,
"Forecast",
"USD"
],
[
218.68795741935486,
20180331,
"Forecast",
"USD"
],
[
0.14384913581657052,
20180401,
"Forecast",
"USD"
],
[
0.009865586851323632,
20180429,
"Forecast",
"USD"
]
]
}
}
ResourceGroupForecast
Solicitud de ejemplo
POST https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/ScreenSharingTest-peer/providers/Microsoft.CostManagement/forecast?api-version=2025-03-01
{
"type": "Usage",
"dataset": {
"aggregation": {
"totalCost": {
"name": "Cost",
"function": "Sum"
}
},
"filter": {
"and": [
{
"or": [
{
"dimensions": {
"name": "ResourceLocation",
"operator": "In",
"values": [
"East US",
"West Europe"
]
}
},
{
"tags": {
"name": "Environment",
"operator": "In",
"values": [
"UAT",
"Prod"
]
}
}
]
},
{
"dimensions": {
"name": "ResourceGroup",
"operator": "In",
"values": [
"API"
]
}
}
]
},
"granularity": "Daily"
},
"includeActualCost": false,
"includeFreshPartialCost": false,
"timePeriod": {
"from": "2022-08-01T00:00:00+00:00",
"to": "2022-08-31T23:59:59+00:00"
},
"timeframe": "Custom"
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.costmanagement import CostManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-costmanagement
# USAGE
python resource_group_forecast.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = CostManagementClient(
credential=DefaultAzureCredential(),
)
response = client.forecast.usage(
scope="subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/ScreenSharingTest-peer",
parameters={
"dataset": {
"aggregation": {"totalCost": {"function": "Sum", "name": "Cost"}},
"filter": {
"and": [
{
"or": [
{
"dimensions": {
"name": "ResourceLocation",
"operator": "In",
"values": ["East US", "West Europe"],
}
},
{"tags": {"name": "Environment", "operator": "In", "values": ["UAT", "Prod"]}},
]
},
{"dimensions": {"name": "ResourceGroup", "operator": "In", "values": ["API"]}},
]
},
"granularity": "Daily",
},
"includeActualCost": False,
"includeFreshPartialCost": False,
"timePeriod": {"from": "2022-08-01T00:00:00+00:00", "to": "2022-08-31T23:59:59+00:00"},
"timeframe": "Custom",
"type": "Usage",
},
)
print(response)
# x-ms-original-file: 2025-03-01/ResourceGroupForecast.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcostmanagement_test
import (
"context"
"log"
"time"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/costmanagement/armcostmanagement/v3"
)
// Generated from example definition: 2025-03-01/ResourceGroupForecast.json
func ExampleForecastClient_Usage_resourceGroupForecast() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcostmanagement.NewClientFactory(cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewForecastClient().Usage(ctx, "subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/ScreenSharingTest-peer", armcostmanagement.ForecastDefinition{
Type: to.Ptr(armcostmanagement.ForecastTypeUsage),
Dataset: &armcostmanagement.ForecastDataset{
Aggregation: map[string]*armcostmanagement.ForecastAggregation{
"totalCost": {
Name: to.Ptr(armcostmanagement.FunctionNameCost),
Function: to.Ptr(armcostmanagement.FunctionTypeSum),
},
},
Filter: &armcostmanagement.ForecastFilter{
And: []*armcostmanagement.ForecastFilter{
{
Or: []*armcostmanagement.ForecastFilter{
{
Dimensions: &armcostmanagement.ForecastComparisonExpression{
Name: to.Ptr("ResourceLocation"),
Operator: to.Ptr(armcostmanagement.ForecastOperatorTypeIn),
Values: []*string{
to.Ptr("East US"),
to.Ptr("West Europe"),
},
},
},
{
Tags: &armcostmanagement.ForecastComparisonExpression{
Name: to.Ptr("Environment"),
Operator: to.Ptr(armcostmanagement.ForecastOperatorTypeIn),
Values: []*string{
to.Ptr("UAT"),
to.Ptr("Prod"),
},
},
},
},
},
{
Dimensions: &armcostmanagement.ForecastComparisonExpression{
Name: to.Ptr("ResourceGroup"),
Operator: to.Ptr(armcostmanagement.ForecastOperatorTypeIn),
Values: []*string{
to.Ptr("API"),
},
},
},
},
},
Granularity: to.Ptr(armcostmanagement.GranularityTypeDaily),
},
IncludeActualCost: to.Ptr(false),
IncludeFreshPartialCost: to.Ptr(false),
TimePeriod: &armcostmanagement.ForecastTimePeriod{
From: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-01T00:00:00+00:00"); return t }()),
To: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-31T23:59:59+00:00"); return t }()),
},
Timeframe: to.Ptr(armcostmanagement.ForecastTimeframeCustom),
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcostmanagement.ForecastClientUsageResponse{
// ForecastResult: armcostmanagement.ForecastResult{
// Name: to.Ptr("55312978-ba1b-415c-9304-cfd9c43c0481"),
// Type: to.Ptr("Microsoft.CostManagement/query"),
// ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/ScreenSharingTest-peer/providers/Microsoft.CostManagement/query/00000000-0000-0000-0000-000000000000"),
// Properties: &armcostmanagement.ForecastProperties{
// Columns: []*armcostmanagement.ForecastColumn{
// {
// Name: to.Ptr("PreTaxCost"),
// Type: to.Ptr("Number"),
// },
// {
// Name: to.Ptr("UsageDate"),
// Type: to.Ptr("Number"),
// },
// {
// Name: to.Ptr("CostStatus"),
// Type: to.Ptr("String"),
// },
// {
// Name: to.Ptr("Currency"),
// Type: to.Ptr("String"),
// },
// },
// Rows: [][]any{
// []any{
// 2.10333307059661,
// 20180331,
// "Forecast",
// "USD",
// },
// },
// },
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { CostManagementClient } = require("@azure/arm-costmanagement");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to lists the forecast charges for scope defined.
*
* @summary lists the forecast charges for scope defined.
* x-ms-original-file: 2025-03-01/ResourceGroupForecast.json
*/
async function resourceGroupForecast() {
const credential = new DefaultAzureCredential();
const client = new CostManagementClient(credential);
const result = await client.forecast.usage(
"subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/ScreenSharingTest-peer",
{
type: "Usage",
dataset: {
aggregation: { totalCost: { name: "Cost", function: "Sum" } },
filter: {
and: [
{
or: [
{
dimensions: {
name: "ResourceLocation",
operator: "In",
values: ["East US", "West Europe"],
},
},
{ tags: { name: "Environment", operator: "In", values: ["UAT", "Prod"] } },
],
},
{ dimensions: { name: "ResourceGroup", operator: "In", values: ["API"] } },
],
},
granularity: "Daily",
},
includeActualCost: false,
includeFreshPartialCost: false,
timePeriod: {
from: new Date("2022-08-01T00:00:00+00:00"),
to: new Date("2022-08-31T23:59:59+00:00"),
},
timeframe: "Custom",
},
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Respuesta de muestra
{
"name": "55312978-ba1b-415c-9304-cfd9c43c0481",
"type": "Microsoft.CostManagement/query",
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/ScreenSharingTest-peer/providers/Microsoft.CostManagement/query/00000000-0000-0000-0000-000000000000",
"properties": {
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "UsageDate",
"type": "Number"
},
{
"name": "CostStatus",
"type": "String"
},
{
"name": "Currency",
"type": "String"
}
],
"nextLink": null,
"rows": [
[
2.10333307059661,
20180331,
"Forecast",
"USD"
]
]
}
}
SubscriptionForecast
Solicitud de ejemplo
POST https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.CostManagement/forecast?api-version=2025-03-01
{
"type": "Usage",
"dataset": {
"aggregation": {
"totalCost": {
"name": "Cost",
"function": "Sum"
}
},
"filter": {
"and": [
{
"or": [
{
"dimensions": {
"name": "ResourceLocation",
"operator": "In",
"values": [
"East US",
"West Europe"
]
}
},
{
"tags": {
"name": "Environment",
"operator": "In",
"values": [
"UAT",
"Prod"
]
}
}
]
},
{
"dimensions": {
"name": "ResourceGroup",
"operator": "In",
"values": [
"API"
]
}
}
]
},
"granularity": "Daily"
},
"includeActualCost": false,
"includeFreshPartialCost": false,
"timePeriod": {
"from": "2022-08-01T00:00:00+00:00",
"to": "2022-08-31T23:59:59+00:00"
},
"timeframe": "Custom"
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.costmanagement import CostManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-costmanagement
# USAGE
python subscription_forecast.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = CostManagementClient(
credential=DefaultAzureCredential(),
)
response = client.forecast.usage(
scope="subscriptions/00000000-0000-0000-0000-000000000000",
parameters={
"dataset": {
"aggregation": {"totalCost": {"function": "Sum", "name": "Cost"}},
"filter": {
"and": [
{
"or": [
{
"dimensions": {
"name": "ResourceLocation",
"operator": "In",
"values": ["East US", "West Europe"],
}
},
{"tags": {"name": "Environment", "operator": "In", "values": ["UAT", "Prod"]}},
]
},
{"dimensions": {"name": "ResourceGroup", "operator": "In", "values": ["API"]}},
]
},
"granularity": "Daily",
},
"includeActualCost": False,
"includeFreshPartialCost": False,
"timePeriod": {"from": "2022-08-01T00:00:00+00:00", "to": "2022-08-31T23:59:59+00:00"},
"timeframe": "Custom",
"type": "Usage",
},
)
print(response)
# x-ms-original-file: 2025-03-01/SubscriptionForecast.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcostmanagement_test
import (
"context"
"log"
"time"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/costmanagement/armcostmanagement/v3"
)
// Generated from example definition: 2025-03-01/SubscriptionForecast.json
func ExampleForecastClient_Usage_subscriptionForecast() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcostmanagement.NewClientFactory(cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewForecastClient().Usage(ctx, "subscriptions/00000000-0000-0000-0000-000000000000", armcostmanagement.ForecastDefinition{
Type: to.Ptr(armcostmanagement.ForecastTypeUsage),
Dataset: &armcostmanagement.ForecastDataset{
Aggregation: map[string]*armcostmanagement.ForecastAggregation{
"totalCost": {
Name: to.Ptr(armcostmanagement.FunctionNameCost),
Function: to.Ptr(armcostmanagement.FunctionTypeSum),
},
},
Filter: &armcostmanagement.ForecastFilter{
And: []*armcostmanagement.ForecastFilter{
{
Or: []*armcostmanagement.ForecastFilter{
{
Dimensions: &armcostmanagement.ForecastComparisonExpression{
Name: to.Ptr("ResourceLocation"),
Operator: to.Ptr(armcostmanagement.ForecastOperatorTypeIn),
Values: []*string{
to.Ptr("East US"),
to.Ptr("West Europe"),
},
},
},
{
Tags: &armcostmanagement.ForecastComparisonExpression{
Name: to.Ptr("Environment"),
Operator: to.Ptr(armcostmanagement.ForecastOperatorTypeIn),
Values: []*string{
to.Ptr("UAT"),
to.Ptr("Prod"),
},
},
},
},
},
{
Dimensions: &armcostmanagement.ForecastComparisonExpression{
Name: to.Ptr("ResourceGroup"),
Operator: to.Ptr(armcostmanagement.ForecastOperatorTypeIn),
Values: []*string{
to.Ptr("API"),
},
},
},
},
},
Granularity: to.Ptr(armcostmanagement.GranularityTypeDaily),
},
IncludeActualCost: to.Ptr(false),
IncludeFreshPartialCost: to.Ptr(false),
TimePeriod: &armcostmanagement.ForecastTimePeriod{
From: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-01T00:00:00+00:00"); return t }()),
To: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-31T23:59:59+00:00"); return t }()),
},
Timeframe: to.Ptr(armcostmanagement.ForecastTimeframeCustom),
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcostmanagement.ForecastClientUsageResponse{
// ForecastResult: armcostmanagement.ForecastResult{
// Name: to.Ptr("55312978-ba1b-415c-9304-cfd9c43c0481"),
// Type: to.Ptr("Microsoft.CostManagement/query"),
// ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.CostManagement/query/00000000-0000-0000-0000-000000000000"),
// Properties: &armcostmanagement.ForecastProperties{
// Columns: []*armcostmanagement.ForecastColumn{
// {
// Name: to.Ptr("PreTaxCost"),
// Type: to.Ptr("Number"),
// },
// {
// Name: to.Ptr("UsageDate"),
// Type: to.Ptr("Number"),
// },
// {
// Name: to.Ptr("CostStatus"),
// Type: to.Ptr("String"),
// },
// {
// Name: to.Ptr("Currency"),
// Type: to.Ptr("String"),
// },
// },
// Rows: [][]any{
// []any{
// 2.10333307059661,
// 20180331,
// "Forecast",
// "USD",
// },
// []any{
// 218.68795741935486,
// 20180331,
// "Forecast",
// "USD",
// },
// []any{
// 0.14384913581657052,
// 20180401,
// "Forecast",
// "USD",
// },
// []any{
// 0.009865586851323632,
// 20180429,
// "Forecast",
// "USD",
// },
// },
// },
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { CostManagementClient } = require("@azure/arm-costmanagement");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to lists the forecast charges for scope defined.
*
* @summary lists the forecast charges for scope defined.
* x-ms-original-file: 2025-03-01/SubscriptionForecast.json
*/
async function subscriptionForecast() {
const credential = new DefaultAzureCredential();
const client = new CostManagementClient(credential);
const result = await client.forecast.usage("subscriptions/00000000-0000-0000-0000-000000000000", {
type: "Usage",
dataset: {
aggregation: { totalCost: { name: "Cost", function: "Sum" } },
filter: {
and: [
{
or: [
{
dimensions: {
name: "ResourceLocation",
operator: "In",
values: ["East US", "West Europe"],
},
},
{ tags: { name: "Environment", operator: "In", values: ["UAT", "Prod"] } },
],
},
{ dimensions: { name: "ResourceGroup", operator: "In", values: ["API"] } },
],
},
granularity: "Daily",
},
includeActualCost: false,
includeFreshPartialCost: false,
timePeriod: {
from: new Date("2022-08-01T00:00:00+00:00"),
to: new Date("2022-08-31T23:59:59+00:00"),
},
timeframe: "Custom",
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Respuesta de muestra
{
"name": "55312978-ba1b-415c-9304-cfd9c43c0481",
"type": "Microsoft.CostManagement/query",
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.CostManagement/query/00000000-0000-0000-0000-000000000000",
"properties": {
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "UsageDate",
"type": "Number"
},
{
"name": "CostStatus",
"type": "String"
},
{
"name": "Currency",
"type": "String"
}
],
"nextLink": null,
"rows": [
[
2.10333307059661,
20180331,
"Forecast",
"USD"
],
[
218.68795741935486,
20180331,
"Forecast",
"USD"
],
[
0.14384913581657052,
20180401,
"Forecast",
"USD"
],
[
0.009865586851323632,
20180429,
"Forecast",
"USD"
]
]
}
}
Definiciones
| Nombre |
Description |
|
ErrorDetails
|
Detalles del error.
|
|
ErrorResponse
|
La respuesta de error indica que el servicio no puede procesar la solicitud entrante. El motivo se proporciona en el mensaje de error. \n\nAlgunas respuestas a errores: \n\n * 429 TooManyRequests - La solicitud está limitada. Vuelva a intentarlo después de esperar el tiempo especificado en el encabezado "x-ms-ratelimit-microsoft.consumption-retry-after". \n\n * 503 ServiceNo disponible - El servicio está temporalmente no disponible. Vuelva a intentarlo después de esperar el tiempo especificado en el encabezado "Retry-After".
|
|
ForecastAggregation
|
Expresión de agregación que se va a usar en la previsión.
|
|
ForecastColumn
|
Propiedades de columna de previsión
|
|
ForecastComparisonExpression
|
Expresión de comparación que se va a usar en la previsión.
|
|
ForecastDataset
|
Definición de los datos presentes en la previsión.
|
|
ForecastDatasetConfiguration
|
Configuración del conjunto de datos en la previsión.
|
|
ForecastDefinition
|
Definición de una previsión.
|
|
ForecastFilter
|
Expresión de filtro que se va a usar en la exportación.
|
|
ForecastOperatorType
|
Operador que se va a usar para la comparación.
|
|
ForecastResult
|
Resultado de la previsión. Contiene todas las columnas enumeradas en agrupaciones y agregaciones.
|
|
ForecastTimeframe
|
Período de tiempo para extraer datos para la previsión.
|
|
ForecastTimePeriod
|
Tiene un período de tiempo para extraer datos para la previsión.
|
|
ForecastType
|
Tipo de la previsión.
|
|
FunctionName
|
Nombre de la columna que se va a agregar.
|
|
FunctionType
|
Nombre de la función de agregación que se va a usar.
|
|
GranularityType
|
Granularidad de las filas de la exportación. Actualmente se admite "Daily" para la mayoría de los casos.
|
ErrorDetails
Objeto
Detalles del error.
| Nombre |
Tipo |
Description |
|
code
|
string
|
Código de error.
|
|
message
|
string
|
Mensaje de error que indica por qué se produjo un error en la operación.
|
ErrorResponse
Objeto
La respuesta de error indica que el servicio no puede procesar la solicitud entrante. El motivo se proporciona en el mensaje de error. \n\nAlgunas respuestas a errores: \n\n * 429 TooManyRequests - La solicitud está limitada. Vuelva a intentarlo después de esperar el tiempo especificado en el encabezado "x-ms-ratelimit-microsoft.consumption-retry-after". \n\n * 503 ServiceNo disponible - El servicio está temporalmente no disponible. Vuelva a intentarlo después de esperar el tiempo especificado en el encabezado "Retry-After".
| Nombre |
Tipo |
Description |
|
error
|
ErrorDetails
|
Detalles del error.
|
ForecastAggregation
Objeto
Expresión de agregación que se va a usar en la previsión.
| Nombre |
Tipo |
Description |
|
function
|
FunctionType
|
Nombre de la función de agregación que se va a usar.
|
|
name
|
FunctionName
|
Nombre de la columna que se va a agregar.
|
ForecastColumn
Objeto
Propiedades de columna de previsión
| Nombre |
Tipo |
Description |
|
name
|
string
|
Nombre de la columna.
|
|
type
|
string
|
Tipo de columna.
|
ForecastComparisonExpression
Objeto
Expresión de comparación que se va a usar en la previsión.
| Nombre |
Tipo |
Description |
|
name
|
string
|
Nombre de la columna que se va a usar en comparación.
|
|
operator
|
ForecastOperatorType
|
Operador que se va a usar para la comparación.
|
|
values
|
string[]
|
Matriz de valores que se van a usar para la comparación
|
ForecastDataset
Objeto
Definición de los datos presentes en la previsión.
| Nombre |
Tipo |
Description |
|
aggregation
|
<string,
ForecastAggregation>
|
Diccionario de expresiones de agregación que se van a usar en la previsión. La clave de cada elemento del diccionario es el alias de la columna agregada. la previsión puede tener hasta 2 cláusulas de agregación.
|
|
configuration
|
ForecastDatasetConfiguration
|
Tiene información de configuración para los datos de la exportación. La configuración se omitirá si se proporcionan la agregación y la agrupación.
|
|
filter
|
ForecastFilter
|
Tiene la expresión de filtro que se va a usar en la previsión.
|
|
granularity
|
GranularityType
|
Granularidad de las filas de la previsión.
|
ForecastDatasetConfiguration
Objeto
Configuración del conjunto de datos en la previsión.
| Nombre |
Tipo |
Description |
|
columns
|
string[]
|
Matriz de nombres de columna que se van a incluir en la previsión. Se permite cualquier nombre de columna de previsión válido. Si no se proporciona, la previsión incluye todas las columnas.
|
ForecastDefinition
Objeto
Definición de una previsión.
| Nombre |
Tipo |
Description |
|
dataset
|
ForecastDataset
|
Tiene definición para los datos de esta previsión.
|
|
includeActualCost
|
boolean
|
Valor booleano que determina si se incluirá realCost.
|
|
includeFreshPartialCost
|
boolean
|
Valor booleano que determina si FreshPartialCost se incluirá.
|
|
timePeriod
|
ForecastTimePeriod
|
Tiene un período de tiempo para extraer datos para la previsión.
|
|
timeframe
|
ForecastTimeframe
|
Período de tiempo para extraer datos para la previsión. Si es personalizado, se debe proporcionar un período de tiempo específico.
|
|
type
|
ForecastType
|
Tipo de la previsión.
|
ForecastFilter
Objeto
Expresión de filtro que se va a usar en la exportación.
ForecastOperatorType
Enumeración
Operador que se va a usar para la comparación.
ForecastResult
Objeto
Resultado de la previsión. Contiene todas las columnas enumeradas en agrupaciones y agregaciones.
| Nombre |
Tipo |
Description |
|
eTag
|
string
|
ETag del recurso.
|
|
id
|
string
|
Identificador de recurso.
|
|
location
|
string
|
Ubicación del recurso.
|
|
name
|
string
|
Nombre del recurso.
|
|
properties.columns
|
ForecastColumn[]
|
Matriz de columnas
|
|
properties.nextLink
|
string
|
Vínculo (url) a la página siguiente de resultados.
|
|
properties.rows
|
Rows[]
|
Matriz de filas
|
|
sku
|
string
|
SKU del recurso.
|
|
tags
|
object
|
Etiquetas de recursos.
|
|
type
|
string
|
Tipo de recurso.
|
ForecastTimeframe
Enumeración
Período de tiempo para extraer datos para la previsión.
ForecastTimePeriod
Objeto
Tiene un período de tiempo para extraer datos para la previsión.
| Nombre |
Tipo |
Description |
|
from
|
string
(date-time)
|
Fecha de inicio de la que se van a extraer datos.
|
|
to
|
string
(date-time)
|
Fecha de finalización a la que se van a extraer los datos.
|
ForecastType
Enumeración
Tipo de la previsión.
| Valor |
Description |
|
Usage
|
|
|
ActualCost
|
|
|
AmortizedCost
|
|
FunctionName
Enumeración
Nombre de la columna que se va a agregar.
| Valor |
Description |
|
PreTaxCostUSD
|
|
|
Cost
|
|
|
CostUSD
|
|
|
PreTaxCost
|
|
FunctionType
Enumeración
Nombre de la función de agregación que se va a usar.
GranularityType
Enumeración
Granularidad de las filas de la exportación. Actualmente se admite "Daily" para la mayoría de los casos.
| Valor |
Description |
|
Daily
|
|
|
Monthly
|
|