> ## Documentation Index
> Fetch the complete documentation index at: https://docs.requestly.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Set a Response Value as a Variable

> Capture a value straight out of a response body into an environment, collection, or global variable by right-clicking the selection, with no script to write.

A login call returns a token and your next request needs it. Rather than writing a post-response script for that, select the value in the response body, right-click it, and choose **Set as variable**. Requestly saves the selected text to a variable you name, in the scope you pick, ready to use as `{{variable_name}}`.

## Where you can use it

The action lives in the response panel of:

* HTTP requests
* GraphQL requests
* Saved examples of either

Other protocol clients, the Dev Tools network panel, and scheduled-run results do not offer it.

## Capture a value

**1. Send the request**

Send the request and open the **Body** tab of the response panel.

**2. Select the value you want**

Select the text in the response body. The action needs a text view of the body. A picture, a binary placeholder, or an HTML preview blocks the selection. Switch the format selector above the body to **Raw** first.

In a formatted JSON body, a double-click selects the value without its surrounding quote characters. Dragging across the quotes takes them with it, which is also fine: Requestly cleans the selection up for you when it fills the picker. See [Quoted JSON strings are saved without their quotes](#quoted-json-strings-are-saved-without-their-quotes).

**3. Right-click the selection**

Right-click anywhere inside the selection. A short menu opens with **Copy** and **Set as variable**. Choose **Set as variable**.

![A selected token in a JSON response body with the right-click menu open, showing Copy and Set as variable](https://mintcdn.com/requestly/qL6H9DS5yJKdl_V6/images/set-as-variable-menu.light.png?fit=max\&auto=format\&n=qL6H9DS5yJKdl_V6\&q=85\&s=436f065e78dd5387b7acb190fdd1337d)

**4. Name the variable and pick a scope**

The picker opens with your selection already in **Current value**.

* **Name**: type a new name, or pick an existing one from the list for that scope to overwrite it. The list matches on any part of a name, not just the start.
* **Current value**: edit the captured text if you need to. For **String** and **Number** the field accepts line breaks, so a whole JSON object survives an edit intact. **Secret** masks the value in a single-line field, and **Boolean** replaces it with a true/false list.
* **Type**: **String**, **Number**, **Boolean**, or **Secret**.
* **Scope**: **Environment**, **Collection**, or **Global**.

![The Set as variable picker with the Name, Current value, Type, and Scope fields filled in, above the Cancel and Save buttons](https://mintcdn.com/requestly/qL6H9DS5yJKdl_V6/images/set-as-variable-picker.light.png?fit=max\&auto=format\&n=qL6H9DS5yJKdl_V6\&q=85\&s=cf9664fdf602405691e01a09c43b2085)

**5. Save**

Click **Save**. A confirmation names the variable and the scope it went to. **Save** stays disabled until the variable has a name. **Save** is also disabled while the selection is too large, or while no scope is available.

> [!TIP]
>
> **Copy** in the same menu copies exactly what you selected, quote characters included.

## Where the captured value is saved

Every Requestly variable holds two values: an **Initial value (synced)**, which your project shares with your team, and a **Current value (local)**, which stays on the device that set it. [Environment variables](https://docs.requestly.com/api-client/environments-and-variables/environment-variables.md) explains both in full.

**Set as variable** writes your capture to the **Current value** only. The picker has no **Initial value** row for exactly this reason. The captured text is never sent to your team and never written to the shared value, because a bearer token is the main reason to capture a response value in the first place.

![The environment variables table showing the captured token in the Current value column with the Initial value column empty](https://mintcdn.com/requestly/qL6H9DS5yJKdl_V6/images/set-as-variable-saved-value.light.png?fit=max\&auto=format\&n=qL6H9DS5yJKdl_V6\&q=85\&s=6c79369399c53d0a12d2e94fd00a5703)

Two things follow from that:

* A teammate who opens the same project sees the variable name, but not your captured value.
* On your other devices the variable exists with an empty value until you capture it there too.

> [!NOTE]
>
> To share a captured value on purpose, open the variables table and type it into the **Initial value** column yourself.

## Choose a scope

| Scope | Where the value is stored |
| - | - |
| **Environment** | The environment currently selected in the API client sidebar |
| **Collection** | The collection that directly contains this request |
| **Global** | The project's global variables |

The picker offers only the scopes it can write to. **Environment** is missing when no environment is selected. **Collection** is missing for a request that does not sit inside a collection. **Global** is missing until the project has a global environment. When no scope at all is available, the picker shows a message and **Save** stays disabled.

> [!NOTE]
>
> Runtime variables are not offered here. To set one from a response, use a post-response script - see [Runtime variables](https://docs.requestly.com/api-client/environments-and-variables/runtime-variables.md).

## Quoted JSON strings are saved without their quotes

When your selection is exactly one JSON string, Requestly fills the picker with the string itself: the wrapping quotes are removed and escape sequences are resolved. A token therefore never gets saved with quote characters wrapped around it.

| You select | The picker fills in |
| - | - |
| `"eyJhbGciOiJIUzI1NiJ9"` | `eyJhbGciOiJIUzI1NiJ9` |
| `"say \"hi\""` | `say "hi"` |
| `"caf\u00e9"` | `café` |
| `{"a":1}` | `{"a":1}` |
| `12345` | `12345` |

Anything that is not exactly one JSON string is filled in verbatim, as the last two rows show. The value field stays editable either way, so you always see what **Save** will store.

## Overwrite an existing variable

Choosing a name that already exists in the selected scope is an overwrite, not an error. The picker warns you that saving replaces the variable's current value, and **Save** stays enabled. An overwrite:

* replaces the **Current value** with your capture
* leaves the **Initial value** exactly as it was, so your team's shared value is never wiped
* keeps the variable a **Secret** when it already was one, so a masked variable is never unmasked by a capture

## The capture happens once

**Set as variable** stores the text that was on screen when you right-clicked. It is a one-time capture, not a live link to the response, so sending the request again leaves the variable exactly as it is.

> [!NOTE]
>
> For a value that has to refresh on every run, such as a token that expires, use a post-response script instead. See [rq.environment](https://docs.requestly.com/api-client/rq-api-reference/rq-environment.md) and [Scripts](https://docs.requestly.com/api-client/scripts.md).

## Limits

* A name made only of spaces does not count as a name, and **Save** stays disabled.
* A selection over 100,000 characters is refused rather than shortened. Select a smaller part of the body, or use **Copy**.
* The menu appears only over a real selection. Right-click with nothing selected, or with only whitespace selected, and the default context menu appears instead.
* The capture takes the characters shown in the current view. If you switch the body to **Hex** or **Base64** and select there, you capture those characters rather than the decoded text.
* A save can fail when you lack permission to save variables to this project. The picker stays open with a message, so you can try again.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.