wootscootinboogie
wootscootinboogie

Reputation: 8695

GCP Python SDK - Enable APIs without gcloud

I have used the documentation here https://cloud.google.com/endpoints/docs/frameworks/enable-api#gcloud to enable new APIs via the gcloud CLI tool. I have a service account with the owner role over my project, is it possible from within the python SDK, to enable APIs without using gcloud? Or, is it possible to call the gcloud CLI tool from the python SDK?

Upvotes: 0

Views: 536

Answers (2)

marian.vladoi
marian.vladoi

Reputation: 8056

According to the official documentation:

Enabling APIs

You can enable Cloud APIs for a project using the console

You can also enable and disable Cloud APIs using Cloud SDK and Service Usage API

Therefore I would recommend to make a HTTP request using python to this url :POST https://serviceusage.googleapis.com/v1/{name=*/*/services/*}:enable

This is the curl command I used to enable analytics.googleapis.com API

OAUTH_TOKEN=`gcloud auth print-access-token`

curl -X POST -H "Authorization: Bearer $OAUTH_TOKEN" -H "Content-Type: application/json" https://serviceusage.googleapis.com/v1/projects/your-project/services/analytics.googleapis.com:enable


Response body
.......
"state": "ENABLED",
      "parent": "projects/xxxxxxx"

.

Upvotes: 1

guillaume blaquiere
guillaume blaquiere

Reputation: 75715

You can by using the discovery API client library for Service Usage API

You can also perform an authenticated call to the Service Usage API enable service endpoint

Let me know if you have issues and you want code example.

Upvotes: 2

Related Questions