# 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).

from datetime import datetime
import oci

# 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
request_usage_carbon_emissions_response = usage_api_client.request_usage_carbon_emissions(
    request_usage_carbon_emissions_details=oci.usage_api.models.RequestUsageCarbonEmissionsDetails(
        tenant_id="ocid1.test.oc1..<unique_ID>EXAMPLE-tenantId-Value",
        time_usage_started=datetime.strptime(
            "2003-02-14T09:02:24.636Z",
            "%Y-%m-%dT%H:%M:%S.%fZ"),
        time_usage_ended=datetime.strptime(
            "2041-12-11T21:40:02.786Z",
            "%Y-%m-%dT%H:%M:%S.%fZ"),
        emission_calculation_method="SPEND_BASED",
        emission_type="LOCATION_BASED",
        granularity="MONTHLY",
        is_aggregate_by_time=True,
        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,
        filter=oci.usage_api.models.Filter(
            operator="NOT",
            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")])),
    opc_request_id="G9NBXG9YO1QGTOHEBFZ7<unique_ID>",
    page="EXAMPLE-page-Value",
    limit=574)

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

Was this article helpful?