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 Owner permission, which allows you to allow you to create and delete datasets. The Quickstart guide instead uses a shared, read-only project.
Create or select a project
Enable Timeseries Insights API
To use Timeseries Insights API, you must first enable it in the Cloud project you want to use it for:
- Go to the Google Cloud console API Library page.
Go to the API Library page - Select the Cloud project that you want to use to access the service.
- On the API Library page, click Enable.
Configure authorization
A convenient way to authorize your Cloud project to access Timeseries Insights API is to use a service account. To set up, do the following:
- Create a service account.
- Go to the Google Cloud console Service Accounts page.
Go to the Service Accounts page - Select the Cloud project that you want to use to access the service.
- Create a service account. To learn how to create service accounts, see Creating and Managing Service Account.
- Go to the Google Cloud console Service Accounts page.
Grant your new service account the "Timeseries Insights DataSet Owner" role. To learn how to grant roles to service accounts, see Granting Roles to Service Accounts.
The "Timeseries Insights DataSet Owner" role might not be shown on the UI while Timeseries Insights API is in preview. You can use the role ID
roles/timeseriesinsights.datasetsOwner
with the gcloud command to grant the necessary access.gcloud projects add-iam-policy-binding "${PROJECT_ID}" --member="serviceAccount:${SVC_ACCOUNT}" --role=roles/timeseriesinsights.datasetsOwner --condition=None
Configure your local machine.
- Go to the Google Cloud console API Credentials page.
Go to the API Credentials page - 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. - Install oauth2l on your local machine so you can interact with the Google OAuth system.
- Go to the Google Cloud console API Credentials page.
See OAuth 2.0 for detailed documentation about authorization.
Test with curl
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"'
NOTE:
gcurl
is different fromgcurl-demo
in The Quickstart Guide.gcurl-demo
uses the demo project and is authenticated for read-only to the demo project.Set an environment variable
PROJECT_ID
with the identifier of your project:PROJECT_ID="my-project-id"
Ensure that you are logged into 'gcloud':
gcloud auth login
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.