Is it possible to create a new service account key...
# prefect-community
j
Is it possible to create a new service account key from the prefect CLI or the API?
โœ… 1
a
definitely possible from the API because it's possible through UI, but for sure easier to do it via UI
j
Can you share the docs for it? Weโ€™re trying to make a manually executed bash script to configure some environment/infra structure things across our system dynamically.
a
there are no docs for it, you would need to browse interactive API in the Cloud UI
o
you can create an api key like this:
Copy code
def create_api_key(client: prefect.Client, service_account_id: str, service_account: str) -> Tuple[str, str]:
    key_name = f"{service_account}-api-key"
    res = client.graphql(
        {
            "mutation": {
                with_args(
                    "create_api_key",
                    {
                        "input": {
                            "user_id": service_account_id,
                            "name": key_name
                        }
                    }
                ): {
                    "key"
                }
            }
        }
    )
    api_key: str = res["data"]["create_api_key"]["key"]
    return key_name, api_key
๐Ÿ’ฏ 1
๐Ÿ™ 1
a
thanks Oliver ๐Ÿ™Œ