Getting Started

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 gcloud command line interface.
  • 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 the Cloud project you want to use it for:

  1. Go to the Google Cloud Console API Library page.
    Go to the API Library page
  2. Select the Cloud project that you want to use to access the service.
  3. On the API Library page, click Enable.

Configure authorization

To authorize the Service Usage API to access your Cloud project, do the following:

  1. Create a service account.
    1. Go to the Cloud Console Service Accounts page.
      Go to the Service Accounts page
    2. Select the Cloud project that you want to use to access the service.
    3. Create a service account. To learn how to create service accounts, see Creating and Managing Service Account.
  2. Grant your new service account the Service Usage Admin role. To learn how to grant roles to service accounts, see Granting Roles to Service Accounts.
  3. Configure your local machine.

    1. Go to the Cloud Console API Credentials page.
      Go to the API Credentials page
    2. Create a service account key for your new service account and download its JSON credential file to your local machine. The examples in this guide assume the file path is ~/credentials.json. To learn how to create service account keys, see Creating and Managing Service Account Keys.
    3. Install oauth2l on your local machine so you can interact with the Google OAuth system.
    4. Optionally, use oauth2l to create a bearer token using your credential file; this verifies that your OAuth setup is correct and that your service account credential file is valid:

          oauth2l header --json ~/credentials.json cloud-platform

      When successful, the output is similar to the following:

          Authorization: Bearer y29.xxxxxxx

Test with curl

  1. Define a convenient shell alias for calling Google REST APIs:

    alias gcurl='curl -H "$(oauth2l header --json ~/credentials.json cloud-platform" -H "Content-Type: application/json"'
  2. Set an environment variable PROJECT_ID with the identifier of your project:

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

    gcloud auth login
  4. Use gcloud to find the project number for your project and save it in an environment variable:

    PROJECT_NUMBER=`gcloud projects list --filter="${PROJECT_ID}" --format="value(PROJECT_NUMBER)"`
  5. List the enabled APIs and services in this project:

    gcurl "${PROJECT_NUMBER}/services?filter=state:ENABLED&fields=services.config.title,"

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

    "services": [
        "config": {
          "name": "",
          "title": "BigQuery API"
        "config": {
          "name": "",
          "title": "BigQuery Storage API"

Next steps

Follow Listing Services to list the APIs and services that are enabled or available in your Cloud projects.