# This is an automatically generated code sample.
# To make this code sample work in your Oracle Cloud tenancy,
# please replace the values for any parameters whose current values do not fit
# your use case (such as resource IDs, strings containing ‘EXAMPLE’ or ‘unique_id’, and
# boolean, number, and enum parameters with values not fitting your use case).

import oci
from datetime import datetime

# Create a default config using DEFAULT profile in default location
# Refer to
# https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm#SDK_and_CLI_Configuration_File
# for more info
config = oci.config.from_file()


# Initialize service client with default config file
usage_api_client = oci.usage_api.UsageapiClient(config)


# Send the request to service, some parameters are not required, see API
# doc for more info
update_query_response = usage_api_client.update_query(
    update_query_details=oci.usage_api.models.UpdateQueryDetails(
        query_definition=oci.usage_api.models.QueryDefinition(
            display_name="EXAMPLE-displayName-Value",
            report_query=oci.usage_api.models.ReportQuery(
                tenant_id="ocid1.test.oc1..<unique_ID>EXAMPLE-tenantId-Value",
                granularity="HOURLY",
                time_usage_started=datetime.strptime(
                    "2011-12-12T15:23:19.436Z",
                    "%Y-%m-%dT%H:%M:%S.%fZ"),
                time_usage_ended=datetime.strptime(
                    "2030-02-12T00:36:51.261Z",
                    "%Y-%m-%dT%H:%M:%S.%fZ"),
                is_aggregate_by_time=False,
                forecast=oci.usage_api.models.Forecast(
                    time_forecast_ended=datetime.strptime(
                        "2001-02-01T04:33:56.449Z",
                        "%Y-%m-%dT%H:%M:%S.%fZ"),
                    forecast_type="BASIC",
                    time_forecast_started=datetime.strptime(
                        "2014-10-11T10:29:13.653Z",
                        "%Y-%m-%dT%H:%M:%S.%fZ")),
                query_type="CREDIT",
                group_by=["EXAMPLE--Value"],
                group_by_tag=[
                    oci.usage_api.models.Tag(
                        namespace="EXAMPLE-namespace-Value",
                        key="EXAMPLE-key-Value",
                        value="EXAMPLE-value-Value")],
                compartment_depth=2.8949912,
                filter=oci.usage_api.models.Filter(
                    operator="OR",
                    dimensions=[
                        oci.usage_api.models.Dimension(
                            key="EXAMPLE-key-Value",
                            value="EXAMPLE-value-Value")],
                    tags=[
                        oci.usage_api.models.Tag(
                            namespace="EXAMPLE-namespace-Value",
                            key="EXAMPLE-key-Value",
                            value="EXAMPLE-value-Value")]),
                date_range_name="LAST_SEVEN_DAYS"),
            cost_analysis_ui=oci.usage_api.models.CostAnalysisUI(
                graph="STACKED_LINES",
                is_cumulative_graph=False),
            version=3169.5623)),
    query_id="ocid1.test.oc1..<unique_ID>EXAMPLE-queryId-Value",
    opc_request_id="QKMQ6ZVAUJJKSKLQ5T6X<unique_ID>",
    if_match="EXAMPLE-ifMatch-Value")

# Get the data from response
print(update_query_response.data)

Was this article helpful?