# Buggy code
def create_token(name, role):
    """
    Create a Prefect Cloud API token.

    For more info on API tokens visit https://docs.prefect.io/cloud/concepts/api.html

    \b
    Options:
        --name, -n      TEXT    A name to give the generated token
        --role, -r      TEXT    A role for the token
    """
    check_override_auth_token()

    client = Client()

    output = client.graphql(
        query={
            "mutation($input: create_api_token_input!)": {
                "create_api_token(input: $input)": {"token"}
            }
        },
        variables=dict(input=dict(name=name, role=role)),
    )

    if not output.get("data", None):
        click.secho("Issue creating API token", fg="red")
        return

    click.echo(output.data.create_api_token.token)


# Traceback (requests.exceptions.HTTPError)
(default) prefect auth login -t $(cat token)
Login successful!
(default) prefect auth create-token -n my-runner-token -r RUNNER
Traceback (most recent call last):
File "/opt/continuum/anaconda/envs/default/bin/prefect", line 6, in <module>
exit(cli())
File "/opt/continuum/anaconda/envs/default/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/opt/continuum/anaconda/envs/default/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/opt/continuum/anaconda/envs/default/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/opt/continuum/anaconda/envs/default/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/opt/continuum/anaconda/envs/default/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/opt/continuum/anaconda/envs/default/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/opt/continuum/anaconda/envs/default/lib/python3.8/site-packages/prefect/cli/auth.py", line 201, in create_token
output = client.graphql(
File "/opt/continuum/anaconda/envs/default/lib/python3.8/site-packages/prefect/client/client.py", line 212, in graphql
result = self.post(
File "/opt/continuum/anaconda/envs/default/lib/python3.8/site-packages/prefect/client/client.py", line 171, in post
response = self._request(
File "/opt/continuum/anaconda/envs/default/lib/python3.8/site-packages/prefect/client/client.py", line 314, in _request
response.raise_for_status()
File "/opt/continuum/anaconda/envs/default/lib/python3.8/site-packages/requests/models.py", line 941, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.prefect.io/graphql/alpha

# Fixed code
def create_token(name, scope):
    """
    Create a Prefect Cloud API token.

    For more info on API tokens visit https://docs.prefect.io/orchestration/concepts/api.html

    \b
    Options:
        --name, -n      TEXT    A name to give the generated token
        --scope, -r     TEXT    A scope for the token
    """
    check_override_auth_token()

    client = Client()

    output = client.graphql(
        query={
            "mutation($input: create_api_token_input!)": {
                "create_api_token(input: $input)": {"token"}
            }
        },
        variables=dict(input=dict(name=name, scope=scope)),
    )

    if not output.get("data", None):
        click.secho("Issue creating API token", fg="red")
        return

    click.echo(output.data.create_api_token.token)