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. Click Select to choose the Cloud project that you want to use to access the service.
  3. On the API Library page, click Enable.

Create a service account

Create a service account and key to run the curl commands in this section:

  1. Go to the Cloud Console Service Accounts page.
    Go to the Service Accounts page
  2. Click Select to choose 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. To follow the instructions in this section, you must grant the service account the roles/serviceusage.serviceUsageAdmin role. To learn how to grant roles to service accounts, see Granting Roles to Service Accounts.
  4. Go to the Cloud Console API Credentials page.
    go to the API Credentials page
  5. 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.
  6. Install oauth2l on your local machine so you can interact with the Google OAuth system.

Test with curl

  1. Verify your initial setup first:

    oauth2l header --json ~/credentials.json cloud-platform
    
  2. After finishing the OAuth flow, you should see output similar to the following:

    Authorization: Bearer y29.xxxxxxx
    
  3. Define a convenient shell alias for calling Google REST APIs:

    alias gcurl='curl -H "$(oauth2l header --json ~/credentials.json cloud-platform userinfo.email)" -H "Content-Type: application/json"'
    
  4. Try listing available and enabled APIs and services in a project:

    gcurl https://serviceusage.googleapis.com/v1/projects/357084163378/services
    

    If you see a list of services, the setup is successful.

Next steps

Follow Listing Services to list the APIs and services that are enabled or available in your {project_name_short}}s.