Skip to main content

keys

Creates, updates, deletes, gets or lists a keys resource.

Overview

Namekeys
TypeResource
Idgoogle.apikeys.keys

Fields

The following fields are returned by SELECT queries:

Successful response

NameDatatypeDescription
namestringOutput only. The resource name of the key. The name has the form: projects//locations/global/keys/. For example: projects/123456867718/locations/global/keys/b7ff1f9f-8275-410a-94dd-3855ee9b5dd2 NOTE: Key is a global resource; hence the only supported value for location is global.
annotationsobjectAnnotations is an unstructured key-value map stored with a policy that may be set by external tools to store and retrieve arbitrary metadata. They are not queryable and should be preserved when modifying objects.
createTimestring (google-datetime)Output only. A timestamp identifying the time this key was originally created.
deleteTimestring (google-datetime)Output only. A timestamp when this key was deleted. If the resource is not deleted, this must be empty.
displayNamestringHuman-readable display name of this key that you can modify. The maximum length is 63 characters.
etagstringOutput only. A checksum computed by the server based on the current value of the Key resource. This may be sent on update and delete requests to ensure the client has an up-to-date value before proceeding. See https://google.aip.dev/154.
keyStringstringOutput only. An encrypted and signed value held by this key. This field can be accessed only through the GetKeyString method.
restrictionsobjectKey restrictions. (id: V2Restrictions)
serviceAccountEmailstringOptional. The email address of the service account the key is bound to.
uidstringOutput only. Unique id in UUID4 format.
updateTimestring (google-datetime)Output only. A timestamp identifying the time this key was last updated.

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
getselectprojectsId, locationsId, keysIdGets the metadata for an API key. The key string of the API key isn't included in the response. NOTE: Key is a global resource; hence the only supported value for location is global.
listselectprojectsId, locationsIdpageToken, pageSize, showDeletedLists the API keys owned by a project. The key string of the API key isn't included in the response. NOTE: Key is a global resource; hence the only supported value for location is global.
createinsertprojectsId, locationsIdkeyIdCreates a new API key. NOTE: Key is a global resource; hence the only supported value for location is global.
patchupdateprojectsId, locationsId, keysIdupdateMaskPatches the modifiable fields of an API key. The key string of the API key isn't included in the response. NOTE: Key is a global resource; hence the only supported value for location is global.
deletedeleteprojectsId, locationsId, keysIdetagDeletes an API key. Deleted key can be retrieved within 30 days of deletion. Afterward, key will be purged from the project. NOTE: Key is a global resource; hence the only supported value for location is global.
lookup_keyexeckeyStringFind the parent project and resource name of the API key that matches the key string in the request. If the API key has been purged, resource name will not be set. The service account must have the apikeys.keys.lookup permission on the parent project.
undeleteexecprojectsId, locationsId, keysIdUndeletes an API key which was deleted within 30 days. NOTE: Key is a global resource; hence the only supported value for location is global.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
keysIdstring
locationsIdstring
projectsIdstring
etagstring
keyIdstring
keyStringstring
pageSizeinteger (int32)
pageTokenstring
showDeletedboolean
updateMaskstring (google-fieldmask)

SELECT examples

Gets the metadata for an API key. The key string of the API key isn't included in the response. NOTE: Key is a global resource; hence the only supported value for location is global.

SELECT
name,
annotations,
createTime,
deleteTime,
displayName,
etag,
keyString,
restrictions,
serviceAccountEmail,
uid,
updateTime
FROM google.apikeys.keys
WHERE projectsId = '{{ projectsId }}' -- required
AND locationsId = '{{ locationsId }}' -- required
AND keysId = '{{ keysId }}' -- required;

INSERT examples

Creates a new API key. NOTE: Key is a global resource; hence the only supported value for location is global.

INSERT INTO google.apikeys.keys (
data__serviceAccountEmail,
data__annotations,
data__restrictions,
data__displayName,
projectsId,
locationsId,
keyId
)
SELECT
'{{ serviceAccountEmail }}',
'{{ annotations }}',
'{{ restrictions }}',
'{{ displayName }}',
'{{ projectsId }}',
'{{ locationsId }}',
'{{ keyId }}'
RETURNING
name,
done,
error,
metadata,
response
;

UPDATE examples

Patches the modifiable fields of an API key. The key string of the API key isn't included in the response. NOTE: Key is a global resource; hence the only supported value for location is global.

UPDATE google.apikeys.keys
SET
data__serviceAccountEmail = '{{ serviceAccountEmail }}',
data__annotations = '{{ annotations }}',
data__restrictions = '{{ restrictions }}',
data__displayName = '{{ displayName }}'
WHERE
projectsId = '{{ projectsId }}' --required
AND locationsId = '{{ locationsId }}' --required
AND keysId = '{{ keysId }}' --required
AND updateMask = '{{ updateMask}}'
RETURNING
name,
done,
error,
metadata,
response;

DELETE examples

Deletes an API key. Deleted key can be retrieved within 30 days of deletion. Afterward, key will be purged from the project. NOTE: Key is a global resource; hence the only supported value for location is global.

DELETE FROM google.apikeys.keys
WHERE projectsId = '{{ projectsId }}' --required
AND locationsId = '{{ locationsId }}' --required
AND keysId = '{{ keysId }}' --required
AND etag = '{{ etag }}';

Lifecycle Methods

Find the parent project and resource name of the API key that matches the key string in the request. If the API key has been purged, resource name will not be set. The service account must have the apikeys.keys.lookup permission on the parent project.

EXEC google.apikeys.keys.lookup_key 
@keyString='{{ keyString }}';