Skip to content Skip to sidebar Skip to footer

Rest Api Google Cloud- Create/edit/list Api Keys

I'm trying to create an API to manage API Keys from inside a VM instance, so I'm looking for a programmatic and/or using Google REST APIS way to create, delete and list Google Clou

Solution 1:

AFAIK, API-KEYS REST documentation has not been published yet.

Disclaimer: alpha status APIs are subject to change. Your code might break in the future.

I recommend creating a new Google Cloud Project to do your testing in.

The following examples are for Windows. The concepts are the same for Linux and macOS.

We need a couple of variables setup:

# Your Project IDset GCP_PROJECT=my-project-123456# Google OAuth Access Token# Fancy DOS batch stuff to fetch a token
call gcloud auth print-access-token > token
set /p GCP_TOKEN=<token
del token

Example #1: Create an API KEY:

setURL=https://apikeys.googleapis.com/v2alpha1/projects/%GCP_PROJECT%/keys?alt=json

curl -XPOST%URL%^-H"Content-Type: application/json"^-H"Authorization: Bearer %GCP_TOKEN%"^-d "{\"displayName\": \"test key\", \"restrictions\": {}}"

Example #2 - List API KEYs:

curl https://apikeys.googleapis.com/v2alpha1/projects/%GCP_PROJECT%/keys?alt=json ^
-H "Accept: application/json" ^
-H "Authorization: Bearer %GCP_TOKEN%"

Example #3 - Delete and API KEY

Note: You will need the KEY name. Use the list example. Use the last part of the list json name key.

set URL=https://apikeys.googleapis.com/v2alpha1/projects/%GCP_PROJECT%/keys

set KEY=2be9ee20-955c-4405-ac0c-e9f8ae1a3839

curl -X DELETE %URL%/%KEY% ^
-H "Content-Type: application/json" ^
-H "Authorization: Bearer %GCP_TOKEN%"

Addition Notes:

There is a v2beta1 API. I have not tested with this version.

Example endpoint:

https://apikeys.googleapis.com/v2beta1/projects/development-219304/keys

Post a Comment for "Rest Api Google Cloud- Create/edit/list Api Keys"