To inspect a report's settings, such as its scope and metrics, or to check its expiry time, use App Optimize API to get the report's metadata.
This API request does not return the actual data rows within the report. To download this information, you need to read the report's data.
Before you begin
-
Verify that you have the permissions required to complete this guide.
Select the tab for how you plan to use the samples in this document:
gcloud
Install the Google Cloud CLI.
Configure the gcloud CLI to use your federated identity.
For more information, see Sign in to the gcloud CLI with your federated identity.
To initialize the gcloud CLI, run the following command:
gcloud initAfter initializing the gcloud CLI, update it and install the required components:
gcloud components update gcloud components install beta
For information about setting up authentication for a production environment, see Set up Application Default Credentials for code running on Google Cloud in the Google Cloud authentication documentation.
Python
- Install the Python client library for App Optimize API.
-
To use the Python samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
-
Install the Google Cloud CLI.
-
-
Configure the gcloud CLI to use your federated identity.
For more information, see Sign in to the gcloud CLI with your federated identity.
-
Create local authentication credentials for your user account:
gcloud auth application-default login
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up ADC for a local development environment in the Google Cloud authentication documentation.
For information about setting up authentication for a production environment, see Set up Application Default Credentials for code running on Google Cloud in the Google Cloud authentication documentation.
REST
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
Install the Google Cloud CLI, and then sign in to the gcloud CLI with your federated identity.
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
For information about setting up authentication for a production environment, see Set up Application Default Credentials for code running on Google Cloud in the Google Cloud authentication documentation.
Required roles
To get the permissions that
you need to read a report's metadata,
ask your administrator to grant you the
App Optimize Viewer (roles/appoptimize.viewer) IAM role on the project that owns the report resource.
For more information about granting roles, see Manage access to projects, folders, and organizations.
You might also be able to get the required permissions through custom roles or other predefined roles.
Get report metadata
To retrieve the metadata for a report, follow the instructions for your preferred method:
gcloud
Use the gcloud beta app-optimize reports describe command to get a
report's metadata.
gcloud beta app-optimize reports describe REPORT_ID \
--project=PROJECT_ID \
--location=global
Replace the following:
PROJECT_ID: the ID of the Google Cloud project that owns the report resource that you want to retrieve.REPORT_ID: the ID of the report to retrieve. This ID was specified when the report was created, and can be obtained by listing reports.
Python
The following Python code uses AppOptimizeClient.get_report() to get
a report's metadata.
from google.cloud import appoptimize_v1beta
project_id = "PROJECT_ID"
report_id = "REPORT_ID"
name = f"projects/{project_id}/locations/global/reports/{report_id}"
# Create the App Optimize client and request the report's metadata
client = appoptimize_v1beta.AppOptimizeClient()
request = appoptimize_v1beta.GetReportRequest(name=name)
response = client.get_report(request=request)
# Display the metadata
print(response)
Replace the following:
PROJECT_ID: the ID of the Google Cloud project that owns the report resource that you want to retrieve.REPORT_ID: the ID of the report to retrieve. This ID was specified when the report was created, and can be obtained by listing reports.
REST
Use the following curl command to get the
report metadata:
curl -H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://appoptimize.googleapis.com/v1beta/projects/PROJECT_ID/locations/global/reports/REPORT_ID"
Replace the following:
PROJECT_ID: the ID of the Google Cloud project that owns the report resource that you want to retrieve.REPORT_ID: the ID of the report to retrieve. This ID was specified when the report was created, and can be obtained by listing reports.
If the request is successful, the API returns a JSON response containing the report metadata. Here is an example successful response, including the dimension and metric selected, the project scope, and when the report is scheduled to expire:
{
"name": "projects/PROJECT_ID/locations/global/reports/REPORT_ID",
"dimensions": [
"location",
"product_display_name",
"project",
"resource",
"resource_type"
],
"scopes": [
{
"project": "projects/PROJECT_ID"
}
],
"filter": "hour >= now - duration(\"168h\")",
"expireTime": "2026-02-05T18:50:25.273833857Z",
"metrics": [
"cost",
"cpu_mean_utilization"
]
}