Setup for Full Access

Stay organized with collections Save and categorize content based on your preferences.

This page describes the basic steps necessary to set up your local environment to experiment with Timeseries Insights API using the curl command.

NOTE: This is a guide to set up a project with the Timeseries Insights DataSet Owner role (roles/timeseriesinsights.datasetsOwner), which allows you to create and delete datasets. The Quickstart guide instead uses a shared, read-only project.

Before you begin

  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. Install the Google Cloud CLI.
  3. To initialize the gcloud CLI, run the following command:

    gcloud init
  4. Create or select a Google Cloud project.

    • Create a Cloud project:

      gcloud projects create PROJECT_ID
    • Select the Cloud project that you created:

      gcloud config set project PROJECT_ID
  5. Enable the Timeseries Insights API:

    gcloud services enable timeseriesinsights.googleapis.com
  6. Set up authentication:

    1. Create the service account:

      gcloud iam service-accounts create NAME

      Replace NAME with a name for the service account.

    2. Grant roles to the service account. Run the following command once for each of the following IAM roles: roles/timeseriesinsights.datasetsOwner :

      gcloud projects add-iam-policy-binding PROJECT_ID --member="serviceAccount:SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com" --role=ROLE

      Replace the following:

      • SERVICE_ACCOUNT_NAME: the name of the service account
      • PROJECT_ID: the project ID where you created the service account
      • ROLE: the role to grant
    3. Grant your Google Account a role that lets you create access tokens for the service account:

      gcloud iam service-accounts add-iam-policy-binding SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com --member="user:USER_EMAIL" --role=roles/iam.serviceAccountTokenCreator

      Replace the following:

      • SERVICE_ACCOUNT_NAME: the name of the service account
      • PROJECT_ID: the project ID where you created the service account
      • USER_EMAIL: your email address
  7. Install the Google Cloud CLI.
  8. To initialize the gcloud CLI, run the following command:

    gcloud init
  9. Create or select a Google Cloud project.

    • Create a Cloud project:

      gcloud projects create PROJECT_ID
    • Select the Cloud project that you created:

      gcloud config set project PROJECT_ID
  10. Enable the Timeseries Insights API:

    gcloud services enable timeseriesinsights.googleapis.com
  11. Set up authentication:

    1. Create the service account:

      gcloud iam service-accounts create NAME

      Replace NAME with a name for the service account.

    2. Grant roles to the service account. Run the following command once for each of the following IAM roles: roles/timeseriesinsights.datasetsOwner :

      gcloud projects add-iam-policy-binding PROJECT_ID --member="serviceAccount:SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com" --role=ROLE

      Replace the following:

      • SERVICE_ACCOUNT_NAME: the name of the service account
      • PROJECT_ID: the project ID where you created the service account
      • ROLE: the role to grant
    3. Grant your Google Account a role that lets you create access tokens for the service account:

      gcloud iam service-accounts add-iam-policy-binding SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com --member="user:USER_EMAIL" --role=roles/iam.serviceAccountTokenCreator

      Replace the following:

      • SERVICE_ACCOUNT_NAME: the name of the service account
      • PROJECT_ID: the project ID where you created the service account
      • USER_EMAIL: your email address

Test with curl

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

    alias gcurl='curl -H "Authorization: Bearer $(gcloud auth print-access-token --impersonate-service-account=SERVICE_ACCOUNT_EMAIL)" -H "Content-Type: application/json"'
    

    NOTE: gcurl is different from gcurl-demo in The Quickstart Guide. gcurl-demo uses the demo project and is authenticated for read-only to the demo project.

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

    PROJECT_ID="my-project-id"
    
  3. List the enabled APIs and services in this project:

    gcurl "https://timeseriesinsights.googleapis.com/v1/projects/${PROJECT_ID}/datasets"
    

    If you do not see an error, then your setup is successful.

Next steps

Follow Tutorial to learn about the API.