Delete a report

A report created by App Optimize API is automatically deleted 24 hours after its creation. However, you can use the API to explicitly delete the report before its scheduled expiry if it's no longer needed.

Once deleted, a report and its data are no longer accessible from App Optimize API.

Before you begin

gcloud

In the Google Cloud console, activate Cloud Shell.

Activate Cloud Shell

At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

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

  1. Install the Python client library for App Optimize API.
  2. 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.

    1. Install the Google Cloud CLI.

    2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

    3. If you're using a local shell, then create local authentication credentials for your user account:

      gcloud auth application-default login

      You don't need to do this if you're using Cloud Shell.

      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.

    If you're using an external identity provider (IdP), you must first 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 delete a report, ask your administrator to grant you the App Optimize Admin (roles/appoptimize.admin) 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.

Delete a report

To delete a report, follow the instructions for your preferred method:

gcloud

Use the gcloud beta app-optimize reports delete command to remove your report.

gcloud beta app-optimize reports delete 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 delete.
  • REPORT_ID: the ID of the report to delete. This ID was specified when the report was created, and can be obtained by listing reports in the project.

Python

The following Python code uses AppOptimizeClient.delete_report() to remove your report.

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 a report deletion
client = appoptimize_v1beta.AppOptimizeClient()
request = appoptimize_v1beta.DeleteReportRequest(name=name)
client.delete_report(request=request)
print(f"Deleted report: {name}")

Replace the following:

  • PROJECT_ID: the ID of the Google Cloud project that owns the report resource that you want to delete.
  • REPORT_ID: the ID of the report to delete. This ID was specified when the report was created, and can be obtained by listing reports in the project.

REST

Use the following curl command to send an HTTP DELETE request to the report's resource endpoint:

curl -X DELETE \
  -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 delete.
  • REPORT_ID: the ID of the report to delete. This ID was specified when the report was created, and can be obtained by listing reports in the project.

If the request is successful, the API returns the empty JSON response {}.

What's next