google-cloud-pythongoogle-cloud-api-keys

What should the 'parent' value be when calling Google's API keys client ListKeysRequest method?


I'm trying to use the google-cloud-api-keys package's ApiKeysClient to get a list of API keys in my project. What should the format of the parent parameter be?

I've tried using my project ID and project number, but I'm getting an API_SHARED_INVALID_PARENT_FORMAT error. I've tried all the following:

client.list_keys(parent='projects/12345') # projects / project number
client.list_keys(parent='projects/my-project') # projects / project ID
client.list_keys(parent='12345') # just the project number
client.list_keys(parent='my-project') # just the project ID

Solution

  • I discovered now that it should be "projects/<project-id>/locations/global" from looking at the source code of an open source project that calls this API route.

    This works:

    from google.cloud import api_keys_v2
    client = api_keys_v2.ApiKeysClient()
    response  = client.list_keys(parent='projects/my-project-id/locations/global')
    for r in response:
        print(r)