https://prefect.io logo
#prefect-community
Title
# prefect-community
j

Josh

07/15/2022, 4:54 PM
Is it possible to create a new service account key from the prefect CLI or the API?
โœ… 1
a

Anna Geller

07/15/2022, 4:58 PM
definitely possible from the API because it's possible through UI, but for sure easier to do it via UI
j

Josh

07/15/2022, 5:05 PM
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

Anna Geller

07/15/2022, 5:10 PM
there are no docs for it, you would need to browse interactive API in the Cloud UI
o

Oliver Mannion

07/16/2022, 1:34 AM
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

Anna Geller

07/16/2022, 12:29 PM
thanks Oliver ๐Ÿ™Œ
12 Views