# How to Update Scenarios

## Prerequisites

1. [Run the agent](https://docs.stoobly.com/guides/how-to-run-the-agent)
2. [Configure the proxy](https://docs.stoobly.com/guides/proxy-configuration)
3. [Record requests to a scenario](https://docs.stoobly.com/guides/how-to-record-requests)

## Why Update Scenarios?

API flows change over time. That is, the composition of a request within the scenario may change e.g. a request may require a new query param. When this happens we need to update the Stoobly to receive the latest updates. This is done in three high-level steps:

1. Configure a scenario to be overwritable
2. Enable recording
3. Manually triggering the scenario or using a test to replay requests

Afterwards, the scenario will be available for use and will contain all the updated requests.

## Updating Scenarios

{% hint style="warning" %}
Before updating a scenario, it is recommended to create a [snapshot](https://docs.stoobly.com/core-concepts/mock-api/snapshots) in case changes need to be reverted.
{% endhint %}

There are two ways to update scenarios, from the UI and from the CLI:

{% content-ref url="how-to-update-scenarios/updating-with-overwrite" %}
[updating-with-overwrite](https://docs.stoobly.com/guides/how-to-update-requests/how-to-update-scenarios/updating-with-overwrite)
{% endcontent-ref %}

{% content-ref url="how-to-update-scenarios/updating-with-replay" %}
[updating-with-replay](https://docs.stoobly.com/guides/how-to-update-requests/how-to-update-scenarios/updating-with-replay)
{% endcontent-ref %}

The first request that gets recorded will overwrite the scenario. Any future recorded request will be appended.

## Persisting Changes

After updating a scenario, you should create a snapshot to persist the changes. This uses the **scenario-specific** snapshot command:

```bash
stoobly-agent scenario snapshot "<SCENARIO-KEY>"
```

For more details on snapshotting, see:

{% content-ref url="../how-to-mock-apis/how-to-snapshot-requests" %}
[how-to-snapshot-requests](https://docs.stoobly.com/guides/how-to-mock-apis/how-to-snapshot-requests)
{% endcontent-ref %}

{% hint style="info" %}
**Note:** There are two different snapshot commands:

* `stoobly-agent request snapshot "<REQUEST-KEY>"` - For snapshotting individual requests
* `stoobly-agent scenario snapshot "<SCENARIO-KEY>"` - For snapshotting entire scenarios
  {% endhint %}

## Reverting Changes

Sometimes you need to revert changes such as when you accidentally record wrong requests to the scenario or overwrite data unintentionally.

Instead of experiencing data loss or corruption, you can reset the scenario back to it's previous snapshotted state.

For more information see our documentation on the snapshots feature:

{% content-ref url="../../core-concepts/mock-api/snapshots" %}
[snapshots](https://docs.stoobly.com/core-concepts/mock-api/snapshots)
{% endcontent-ref %}

### Command

```bash
stoobly-agent scenario reset
```

### Options

```bash
$ stoobly-agent scenario reset --help

Usage: stoobly-agent scenario reset [OPTIONS] SCENARIO_KEY

  Reset a scenario to its snapshot state

Options:
  --force     Toggles whether resources are hard deleted.
  -h, --help  Show this message and exit.
```
