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

# Variables

> Use environment variables as placeholders in your request files to keep credentials and dynamic values out of your request files.

Variables are placeholders that Postchi replaces with values from your active environment when a request runs. You write them as `<variable_name>` and they work anywhere in the request file — URLs, headers, and body fields.

## Syntax

Wrap the variable name in angle brackets:

```text theme={null}
<variable_name>
```

Variable names come from the active environment section in your `environments.cenv` or `secrets.cenv` files.

<Note>
  If a variable is used in a request but not defined in the active environment, Postchi shows an error and does not run the request.
</Note>

***

## Where variables work

| Location        | Example                                          |
| --------------- | ------------------------------------------------ |
| URL segment     | `https://api.example.com/users/<user_id>`        |
| Query parameter | `https://api.example.com/search?q=<search_term>` |
| Header value    | `Authorization: <api_token>`                     |
| JSON body value | `"email": "<email>"`                             |
| Form body value | `username=<username>`                            |

***

## Example

If your active environment contains:

```ini theme={null}
# Production
api_token=Bearer abc123
user_id=42
```

Then this request file:

```http theme={null}
GET /api/users/<user_id>
Authorization: <api_token>
Accept: application/json
```

Resolves to:

```http theme={null}
GET /api/users/42
Authorization: Bearer abc123
Accept: application/json
```

***

## Variables in JSON bodies

In a JSON body, Postchi expects variables to appear as quoted string values. Wrap the placeholder in double quotes:

```http theme={null}
POST https://api.example.com/users
Content-Type: application/json
@body
{
  "name": "<username>",
  "email": "<email>",
  "role": "admin"
}
```

Postchi replaces `"<username>"` with the resolved value wrapped in quotes, keeping the JSON valid.
