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.
6 Answers
Use
gcloud services enable <service name>
Example:
gcloud services enable containerregistry.googleapis.com
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
- 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
...
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
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 " }
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
`
- 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}
-
1learned a few things about gcloud from this thorough response. thank you!– Randy LApr 17, 2017 at 15:46
-
@the0ther Thanks for the feedback. Nice to know it was helpful. Apr 18, 2017 at 16:45
-
1I think this is a good answer, but the commands need to be updated, what worked for me was: gcloud services enable indexing.googleapis.com commands on this answer now provide error: ERROR: (gcloud.service-management.list) The
service-management list
command has been replaced byendpoints services list
andservices list
. Oct 15, 2018 at 17:01 -
@FelipeValdes Thanks for the updates. One has to keep up with the release pace. Oct 17, 2018 at 8:04
-
1
gcloud service-management operations describe
is also been deprecated.gcloud services operations describe operations/acf.XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
works but does not output JSON, instead I gotOperation "operations/acf.XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" finished successfully.
Feb 14, 2019 at 15:34
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.
-
-
1Looking real promising. I especially like this
gcloud service-management list --available
.– Randy LApr 3, 2017 at 16:10 -
7
gcloud service-management
has been deprecated and split off into two separate commands now -gcloud endpoints
andgcloud services
. The latter (gcloud services
) is what to use to enable/disable Google Cloud APIs for a project. Feb 8, 2018 at 2:46
What worked for me for enabling container engine API -
gcloud services enable containerregistry.googleapis.com
Select the project where your application will be registered (see the docs about gcloud config set)
gcloud config set project myProject
To see a list of available services for a project, run:
gcloud services list --available
Enable service in the current project (see the docs about gcloud services enable)
gcloud services enable my-consumed-service