# ACL RESTTOKEN

> Generate a REST token for an existing user.

Use `ACL RESTTOKEN` to get a REST API token for an ACL user you already created, given that user's username and password.

The password is the same value used with `>password` in [`ACL SETUSER`](/redis/commands/server/acl-setuser), which is itself a value produced by [`ACL GENTOKEN`](/redis/commands/server/acl-gentoken); passing the full token string that `GENTOKEN` returned also works. The result is a bearer token scoped to that user's permissions that can be set as `UPSTASH_REDIS_REST_TOKEN`, which is how a database user created for TCP access is also given REST API access. `RESTTOKEN` is an Upstash extension.

## Syntax

```redis
ACL RESTTOKEN <username> <password>
```

## Arguments

| Argument | Required | Repeatable | Description |
| --- | --- | --- | --- |
| `username` | Yes | No | Existing ACL user to generate a REST token for. |
| `password` | Yes | No | That user's password, as set with `>password` in `ACL SETUSER`. |

## Important points

- Returns an error if the username does not exist or the password does not match.
- The returned token carries the same permissions as the underlying user; revoking or narrowing the user with `ACL SETUSER` also affects every token issued for it.

## Response

The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below.

| Protocol | Reply |
| --- | --- |
| RESP2 | Bulk string |
| RESP3 | Bulk string |

<Note>
  Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.
</Note>

## Examples

TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`.

<AccordionGroup>

<Accordion title="Redis CLI" icon="terminal">

```bash
ACL RESTTOKEN app AQIDBAUGBwgJCgsMDQ4PEBESExQVFhc
```

</Accordion>

<Accordion title="@upstash/redis" icon="node-js" iconType="brands">

<Note>
  This command is not supported yet in `@upstash/redis`.
</Note>

</Accordion>

<Accordion title="upstash_redis" icon="python" iconType="brands">

<Note>
  This command is not supported yet in `upstash_redis`.
</Note>

</Accordion>

<Accordion title="ioredis" icon="node-js" iconType="brands">

```ts
import Redis from "ioredis";

const redis = new Redis(process.env.REDIS_URL!);
const result = await redis.acl("RESTTOKEN", "app", "AQIDBAUGBwgJCgsMDQ4PEBESExQVFhc");
console.log(result);
```

</Accordion>

<Accordion title="node-redis" icon="node-js" iconType="brands">

```ts
import { createClient } from "redis";

const client = await createClient({ url: process.env.REDIS_URL })
  .on("error", console.error)
  .connect();
const result = await client.sendCommand(["ACL", "RESTTOKEN", "app", "AQIDBAUGBwgJCgsMDQ4PEBESExQVFhc"]);
console.log(result);
```

</Accordion>

<Accordion title="redis-py" icon="python" iconType="brands">

```python
import os
import redis

client = redis.from_url(os.environ["REDIS_URL"])
result = client.execute_command("ACL", "RESTTOKEN", "app", "AQIDBAUGBwgJCgsMDQ4PEBESExQVFhc")
print(result)
```

</Accordion>

<Accordion title="go-redis" icon="golang" iconType="brands">

```go
package main

import (
    "context"
    "fmt"
    "os"

    "github.com/redis/go-redis/v9"
)

func main() {
    opts, err := redis.ParseURL(os.Getenv("REDIS_URL"))
    if err != nil {
        panic(err)
    }
    client := redis.NewClient(opts)
    result, err := client.Do(context.Background(), "ACL", "RESTTOKEN", "app", "AQIDBAUGBwgJCgsMDQ4PEBESExQVFhc").Result()
    if err != nil {
        panic(err)
    }
    fmt.Println(result)
}
```

</Accordion>

<Accordion title="jedis" icon="java" iconType="brands">

```java
import java.net.URI;
import java.nio.charset.StandardCharsets;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.commands.ProtocolCommand;

ProtocolCommand command = () -> "ACL".getBytes(StandardCharsets.UTF_8);
try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) {
  Object result = jedis.sendCommand(command, "RESTTOKEN", "app", "AQIDBAUGBwgJCgsMDQ4PEBESExQVFhc");
  System.out.println(result);
}
```

</Accordion>

<Accordion title="redis-rs" icon="rust" iconType="brands">

```rust
fn main() -> redis::RedisResult<()> {
    let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set");
    let client = redis::Client::open(url)?;
    let mut connection = client.get_connection()?;

    let mut command = redis::cmd("ACL");
    command.arg("RESTTOKEN");
    command.arg("app");
    command.arg("AQIDBAUGBwgJCgsMDQ4PEBESExQVFhc");
    let result: redis::Value = command.query(&mut connection)?;
    println!("{result:?}");
    Ok(())
}
```

</Accordion>

</AccordionGroup>
