# Replay with the CLI

## Replaying a Request

### Command

```bash
stoobly-agent request replay "<REQUEST-KEY>"
```

### Options

```sh
$ stoobly-agent request replay --help
```

```
Usage: stoobly-agent request replay [OPTIONS] REQUEST_KEY

  Replay a request

Options:
  --format [body|json]            Format replay response.
  --host TEXT                     Rewrite request host.
  --lifecycle-hooks-script-path TEXT
                                  Path to lifecycle hooks script.
  --log-level [debug|info|warning|error]
                                  Log levels can be "debug", "info",
                                  "warning", or "error"

  --overwrite                     Replay request and overwrite existing
                                  response.

  --record                        Replay request and record.
  --save                          Replay request and save to history.
  --scenario-key TEXT             Record to scenario.
  --scheme [http|https]           Rewrite request scheme.
  -h, --help                      Show this message and exit.
```

### Replay but Do Not Save

To replay a request and NOT save it anywhere, run the command with no flags:

```bash
$ stoobly-agent request replay REQUEST_KEY
```

This can be useful for replaying the request before doing any mutating operations to confirm the API changes are expected.

### Replay and Create a New Request

The `--record` flag will replay the original request, but create an entirely new request:

```bash
$ stoobly-agent request replay --record REQUEST_KEY
```

This can be useful if you want to save the request to Stoobly and inspect it as a separate request in the UI. Please be aware that this will not allow you to update the original request with the new one since **it is considered a different request altogether**.

### Replay and Save to Replay History

The `--save` flag will replay the request and save it to the [Replay History](https://docs.stoobly.com/core-concepts/mock-api/requests/replay-history) for that request:

```sh
$ stoobly-agent request replay --save REQUEST_KEY
```

This links the rerecording with the original request **but won't change the response yet**. This enables you to manually overwrite and update the response **later**.

### Replay and Immediately Overwrite

To update a request immediately, use the `--overwrite` flag which will do the same as the `--save` flag AND also set the request's response to that latest replayed instance:

```bash
$ stoobly-agent request replay --overwrite REQUEST_KEY
```

This command option is the most convenient one because it replays, rerecords, and overwrites the response all in one go.

{% hint style="info" %}
**Optional:** After overwriting the request, snapshot it to persist the change for version control, sharing, or rollback:

```bash
stoobly-agent request snapshot "<REQUEST-KEY>"
```

{% endhint %}
