# Dynamic Variables

A dynamic variable is a variable which value is determined when the scenario is run. Apart from other tasks, you can effectively use them for storing authorization tokens or newly created entities. The mechanism consists of two parts - variable assignment and dynamic variables themselves.

### Variable assignment

You can assign a part of your request to a dynamic variable. For now you can do it in [RequestStep](/node-types/request-step.md) nodes only. To illustrate this, let's create a request, that adds a new post and save its id into a dynamic variable.

So let's create the request and send it. Send a POST request to <https://testmace-stage.herokuapp.com/posts> with `{"title":"Our cool post!"}` in its body. The RequestStep node will look like this:

![The RequestStep node after sending a POST request](https://gblobscdn.gitbook.com/assets%2F-Lh_FaVh9XfQJ0p1KqZ1%2F-MEYIyEBJFryLAfjaAZw%2F-MEYK_GMtft1g8RmC33S%2FScreenshot%202020-08-12%20at%2019.42.02.png?alt=media\&token=6eee86f7-43b1-4f13-b525-31b96ebd2af9)

Open the parsed response and click on the id parameter to see the dynamic variables assignment dialog:

![The id parameter context menu](https://gblobscdn.gitbook.com/assets%2F-Lh_FaVh9XfQJ0p1KqZ1%2F-MEYIyEBJFryLAfjaAZw%2F-MEYKqNfCuDUvy9N5T7T%2FScreenshot%202020-08-12%20at%2019.43.21.png?alt=media\&token=2fb21c8d-1c87-42ab-8be3-a094c9d17da1)

Choose Assign to variable. You'll see the variable assignment dialog:

![The dynamic variable assignment dialog](https://gblobscdn.gitbook.com/assets%2F-Lh_FaVh9XfQJ0p1KqZ1%2F-MEYIyEBJFryLAfjaAZw%2F-MEYMwrhUFZ4cGMZD37F%2FScreenshot%202020-08-12%20at%2019.47.53%20copy.png?alt=media\&token=4aa1c973-d83b-4ca3-8a90-7f3ed8c51d28)

You can see the following interface parts.

1. The path to the `$request`where the value is stored.
2. The drop-down list with parents, that you can assign the dynamic variable to.
3. The current value at the given path.
4. The dynamic variable name.

Let's create a variable named `id` at this node.

After assignment you can find the dynamic variable in the list of the chosen node (RequestStep) dynamic variables. See the list in the [variables tab](/variables/user-variables.md) in the Dynamic section:

![The RequestStep node dynamic variables list](https://gblobscdn.gitbook.com/assets%2F-Lh_FaVh9XfQJ0p1KqZ1%2F-MEYIyEBJFryLAfjaAZw%2F-MEYNacfor97fWXr626N%2FScreenshot%202020-08-12%20at%2019.55.26.png?alt=media\&token=63f820db-7c40-40d2-9297-7ffaafa6599b)

To view dynamic variables assigned to a certain node, choose the **Values** section from the **Variables** tab. Here’s how this tab looks like for the **MyService** node from the previous example:

![](https://gblobscdn.gitbook.com/assets%2F-Lh_FaVh9XfQJ0p1KqZ1%2F-MEYIyEBJFryLAfjaAZw%2F-MEYO_ymsIrJ2EG8Jiqb%2FScreenshot%202020-08-12%20at%2019.58.16.png?alt=media\&token=96957808-4530-490c-a1b7-375f38c0a086)

#### Using Dynamic Variables

All dynamic variables available for the chosen node are stored in the `$dynamicVar` variable. For example, to access the `id` variable you should write  `$dynamicVar.id`. Just like with other variables, dynamic variables can be inherited from parents or overridden in child elements.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.testmace.com/variables/user-variables/dynamic-variables.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
