Set up Service Usage for a development environment

This page describes how to set up your development environment to use the Service Usage API.

  • For most operational use cases, the simplest way to enable and disable services is to use Google Cloud console.
  • If you need to create scripts, you can use the Google Cloud CLI.
  • If you need to program against the Service Usage API, use one of the client libraries.
  • To experiment with the API, you can follow the alternative setup instructions in this guide and use the curl command to test the API without setting up a full application development environment.

Set up to call the API directly

This section describes the basic steps necessary to set up your local environment to experiment with the Service Usage API using the curl command. It is aimed at developers who need to program against the Service Usage API.

Enable the Service Usage API

To use the Service Usage API, you must first enable it in your Google Cloud project.

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Enable the Service Usage API.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the API

  4. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  5. Enable the Service Usage API.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the API

  6. Ensure that your user account has been granted the Service Usage Admin role.

Test with curl

  1. Set an environment variable PROJECT_ID with the identifier of your project:

    PROJECT_ID=PROJECT_ID
    

    Replace PROJECT_ID with your Google Cloud project ID or number.

  2. Ensure that you are logged into 'gcloud':

    gcloud auth login
    
  3. List the enabled APIs and services in this project:

    curl -H "Authorization: Bearer $(gcloud auth print-access-token)" "https://serviceusage.googleapis.com/v1/projects/${PROJECT_ID}/services?filter=state:ENABLED&fields=services.config.title,services.config.name"
    

    If you see output like this, then your setup is successful:

    {
    "services": [
      {
        "config": {
          "name": "bigquery.googleapis.com",
          "title": "BigQuery API"
        }
      },
      {
        "config": {
          "name": "bigquerystorage.googleapis.com",
          "title": "BigQuery Storage API"
        }
      },
      ...
    

Next steps

To list the APIs and services that are enabled or available in your Google Cloud projects, see List services.