> ## 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.

# Using Variables in API Requests

Once you've defined variables in Requestly, whether global, environment, collection, or subcollection, you can reference them directly in your API requests. This allows you to dynamically inject values into URLs, headers, request bodies, scripts, and more.

## **Use Variables in API Requests**

### **Step 1: Create or Open a Request**

Create or open an existing request in the **API Client**.

<img src="https://mintcdn.com/requestly/nBAzlC6Az5-SAqsk/images/using-variables-in-api-requests/51b2389d-2186-42d7-99b8-a1fb295df6bb.png?fit=max&auto=format&n=nBAzlC6Az5-SAqsk&q=85&s=5e68dcb615ae96c7edc9639fcf21dd4b" align="center" fullwidth="false" width="2048" height="1065" data-path="images/using-variables-in-api-requests/51b2389d-2186-42d7-99b8-a1fb295df6bb.png" />

### **Step 2: Replace Static Values**

Replace static values with your environment variables using the `{{variable_name}}` syntax.

<img src="https://mintcdn.com/requestly/nBAzlC6Az5-SAqsk/images/using-variables-in-api-requests/f597030e-3b81-4656-8267-182280d2ee76.png?fit=max&auto=format&n=nBAzlC6Az5-SAqsk&q=85&s=a9f3dfa3cc2a667dd8a294078d9790f2" align="center" fullwidth="false" width="2048" height="1065" data-path="images/using-variables-in-api-requests/f597030e-3b81-4656-8267-182280d2ee76.png" />

### **Step 3: View Variable Values**

Hover over a variable to see its resolved value.

<img src="https://mintcdn.com/requestly/nBAzlC6Az5-SAqsk/images/using-variables-in-api-requests/0f1df5b5-d0e1-4cd5-b270-3f6ac6e40507.png?fit=max&auto=format&n=nBAzlC6Az5-SAqsk&q=85&s=7f5b3a24daf1cd147f1d4c8f6713b2a3" align="center" fullwidth="false" width="2048" height="1065" data-path="images/using-variables-in-api-requests/0f1df5b5-d0e1-4cd5-b270-3f6ac6e40507.png" />

## **Test Your Setup**

### **Step 1: Execute the Request**

Click **Send** to execute the request.

### **Step 2: Verify Resolved Values**

Check the resolved values in the **Request Preview** to ensure that variables are substituted correctly.

<img src="https://mintcdn.com/requestly/nBAzlC6Az5-SAqsk/images/using-variables-in-api-requests/9c19eb9d-51f8-4a32-b8db-77fcd3d27a2a.png?fit=max&auto=format&n=nBAzlC6Az5-SAqsk&q=85&s=a566dea9ed790acdca3ffeb1a486bf75" align="center" fullwidth="false" width="2048" height="1065" data-path="images/using-variables-in-api-requests/9c19eb9d-51f8-4a32-b8db-77fcd3d27a2a.png" />

<Tip>
  If a variable isn't resolving, verify that the variable name matches exactly (case-sensitive) and is present in the selected environment.
</Tip>

## **Composite variables**

Composite variables allow you to reference one variable inside another variable's value. This is useful when you want to build dynamic values from other variables.

### **How it works**

Define a variable that references another variable using the `{{variable_name}}` syntax:

| Variable Name  | Value                     |
| -------------- | ------------------------- |
| `base_url`     | `api.example.com`         |
| `api_endpoint` | `https://{{base_url}}/v1` |

When `api_endpoint` is resolved, it becomes `https://api.example.com/v1`.

### **Example: Building dynamic URLs**

You can chain multiple variables together:

| Variable Name | Value                                |
| ------------- | ------------------------------------ |
| `env`         | `staging`                            |
| `region`      | `us-east`                            |
| `base_url`    | `{{env}}.{{region}}.api.example.com` |
| `full_url`    | `https://{{base_url}}/users`         |

The `full_url` resolves to `https://staging.us-east.api.example.com/users`.

### **Circular dependency handling**

If you create circular references (e.g., `var_a = {{var_b}}` and `var_b = {{var_a}}`), Requestly detects this and leaves the variables unresolved to prevent infinite loops.

<Note>
  Autocompletion and syntax highlighting for variable references inside the variables table is not currently supported.
</Note>
