Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Can One Use gcloud To Enable APIs

I'm not able to find a way to use the gcloud command line program to change a project's Enabled APIs. My hunch is that it's going to be in the billing "arena" but I've been trying to find this and having much luck.

like image 868
Randy L Avatar asked Mar 29 '17 18:03

Randy L


People also ask

Can I host an API on Google Cloud?

Endpoints uses Service Management, an infrastructure service of Google Cloud to create and manage APIs and services. To use Endpoints to manage an API, you deploy the API's OpenAPI configuration file to Service Management.

What is needed to access gcp APIs?

To use any of Cloud APIs you've got to have a Google project which is equivalent to a developer account. It works as a recourse container for Google Cloud Platform (GCP) resources and provides an isolation boundary for usage of its services. You can create your project using the Cloud Console.

How do I call API in GCP?

To make an API request, you can either make a direct HTTP request, by using tools like curl or httplib2 , or you can use one of the available client libraries. The image URI has a different project ID ( debian-cloud ) from your project ID because images belong to different projects, depending on the type of image.


3 Answers

Use

gcloud services enable <service name>

gcloud Documentation for this

Example:

gcloud services enable containerregistry.googleapis.com
like image 95
Greg Avatar answered Oct 22 '22 20:10

Greg


Issue For your current default project do gcloud service-management list --enabled to list all available APIs enabled.

$ gcloud service-management list --enabled
Listed 0 items.

If you see something like the above i.e 0 items , then you most likely will be getting the error below for some commands for the project.

ERROR: (gcloud.compute.machine-types.list) Some requests did not succeed:
 - Project {PROJECT_ID} is not found and cannot be used for API calls

Solution What you need to do are the below

  1. list the APIs available for the project that can be enabled

The output is quite lengthy so I suggest you use the global option page-size e.g

$ gcloud service-management list  --available --page-size=10 --sort-by="NAME"
NAME                           TITLE
picker.googleapis.com          Google Picker API
bigquery-json.googleapis.com   BigQuery API
chromewebstore.googleapis.com  Chrome Web Store API
tracing.googleapis.com         Google Tracing API
youtube.googleapis.com         YouTube Data API v3
actions.googleapis.com         Google Actions API
dataflow.googleapis.com        Google Dataflow API
serviceuser.googleapis.com     Google Service User API
fusiontables.googleapis.com    Fusion Tables API
surveys.googleapis.com         Surveys API

NAME                                 TITLE
reseller.googleapis.com              Google Apps Reseller API
speech.googleapis.com                Google Cloud Speech API
appsmarket-component.googleapis.com  Google Apps Marketplace SDK
bigtabletableadmin.googleapis.com    Google Cloud Bigtable Table Admin API
container.googleapis.com             Google Container Engine API
vision.googleapis.com                Google Cloud Vision API
storage-api.googleapis.com           Google Cloud Storage JSON API
weavecompanion.googleapis.com        Weave Companion API
ml.googleapis.com                    Google Cloud Machine Learning Engine
firebaserules.googleapis.com         Firebase Rules API

...
  1. Better still check specific available APIs you need e.g to check for the Google Compute Engine API that I want to enable

    $ gcloud service-management list --available --filter='NAME:compute*' NAME TITLE compute-component.googleapis.com Google Compute Engine API

  2. Enable Billing for the project .

    $ gcloud alpha billing accounts projects link amghouse-some-project-1 --account-id=XXFFXX-B9XX37-2D5DX --format=json { "billingAccountName": "billingAccounts/XXFFXX-B9XX37-2D5DX", "billingEnabled": true, "name": "projects/amghouse-some-project-1 /billingInfo", "projectId": "amghouse-some-project-1 " }

  3. Finally enable the api for your project

`

$gcloud service-management enable compute-component.googleapis.com
Waiting for async operation operations/projectSettings.c6d11ddc-915f-4d66-9b98-237e473e7682 to complete...
Operation finished successfully. The following command can describe the Operation details:
 gcloud service-management operations describe operations/projectSettings.c6d11ddc-915f-4d66-9b98-237e473e7682

`

  1. And for good measure it won't hurt to verify

`

$ gcloud service-management operations describe operations/projectSettings.c6d11ddc-915f-4d66-9b98-237e473e7682 --format=json
        {
          "done": true,
          "metadata": {
            "@type": "type.googleapis.com/google.api.servicemanagement.v1.OperationMetadata",
            "persisted": true,
            "resourceNames": [
              "services/compute-component.googleapis.com/projectSettings/"
            ],
            "startTime": "2017-04-08 23:30:22 WAT"
          },
          "name": "operations/projectSettings.c6d11ddc-915f-4d66-9b98-237e473e7682",
          "response": {
            "@type": "type.googleapis.com/google.api.servicemanagement.v1.EnableServiceResponse"
          }
        }

`

Caution Please note without the project being linked to a billing info , an attempt to enable the api will fail with an error similar to

$ gcloud service-management enable compute-component.googleapis.com
ERROR: (gcloud.service-management.enable) FAILED_PRECONDITION: Operation does not satisfy the following requirements: billing-enabled {Billing must be enabled for activation of service '' in project 'amghouse-bct-sms-1' to proceed., https://console.developers.google.com/project/amghouse-bct-sms-1/settings}
like image 7
Abdurrahman Adebiyi Avatar answered Oct 22 '22 21:10

Abdurrahman Adebiyi


Edit: This has been deprecated. See gcloud services answer.

Check out the service-management surface. See gcloud help service-management for more help, as well as gcloud help service-management enable for help about enabling new services. Use gcloud service-management list to list available services so you can find the name of the service you want to enable.

like image 6
Valentin Avatar answered Oct 22 '22 21:10

Valentin