# How to work with variables

import Tabs from '~/components/tabs/Tabs'
import Code from '~/components/Code/Code.astro'

During the deployment process on [Orchestrator](/en/documentation/products/deploy/orchestrator/), you can work with variables. A variable can be set on an [edge service](#edge-services-variables) and an [edge node](#edge-node-variables).

You can create edge node and edge services variables using:

- [Azion Console](/en/documentation/products/guides/how-to-access-azion-console/)
- [Azion API](https://api.azion.com/)

:::note
The priority is always the edge node variable. So, if you have a variable configured on an edge service and the same variable configured on an edge node, the one on the node will override the one configured on the edge service.
:::

---

## Edge Services variables 

<Tabs client:visible>
    <Fragment slot="tab.console">Console</Fragment>
    <Fragment slot="tab.api">API</Fragment>

<Fragment slot="panel.console">
1. Go to [Azion Console](/en/documentation/products/guides/how-to-access-azion-console/).
2. On the top-left corner, select the **Products menu**, represented by three horizontal lines, and then **Edge Services**.
3. Select the [edge service](/en/documentation/products/guides/deploy/create-edge-service/) to which you want to add a variable.
4. In the **Variables** section, add the following variable:

<Code lang="bash" code="name=azion" />

5. Click the **Save** button.

Now, you've created a variable related to a specific service. You need to access this variable through a resource.

1. Navigate to the **Resources** tab. 
2. Click on **+ Resource** or select the resource to which you wish to use the variable.
3. Enter the **Path** of the resource.
4. Choose the type **Text**.
5. Add the following content to the content block: 

```bash
I am using {{name}} Orchestrator
```

6. Click the **Save** button.
</Fragment>

<Fragment slot="panel.api">
1. Run the following `GET` request in your terminal, replacing `[TOKEN VALUE]` with your [personal token](/en/documentation/products/guides/personal-tokens/) and retrieve the edge service ID to which you wish to add a variable:

<Code lang="bash" code={`
curl --location 'https://api.azionapi.net/edge_services/' \
--header 'Accept: application/json; version=3' \
--header 'Authorization: Token [TOKEN VALUE]'
`} />

2. Create a variable related to the service. Run the following `PATCH` request in your terminal, replacing `[TOKEN VALUE]` with your [personal token](/en/documentation/products/guides/personal-tokens/) and informing the variable's name and value:

```bash
curl --location --request PATCH 'https://api.azionapi.net/edge_services/:id' \
--header 'Accept: application/json; version=3' \
--header 'Authorization: Token [TOKEN VALUE]' \
--header 'Content-Type: application/json' \
--data '{
  "active": true,
  "name": "service",
  "variables": [
    {
      "name": "name",
      "value": "azion"
    }
  ]
}'
```

Now, you've created a variable related to a specific service. You need to access this variable through a resource.

3. Run the following `POST` request in your terminal:

```bash 
curl --location 'https://api.azionapi.net/edge_services/:id/resources' \
--header 'Accept: application/json; version=3' \
--header 'Authorization: Token [TOKEN VALUE]' \
--header 'Content-Type: application/json' \
--data '{
  "content_type": "Text",
  "name": "/resource",
  "content": "I am using {{name}} Orchestrator"
}'
```

Replace `[TOKEN VALUE]` with your [personal token](/en/documentation/products/guides/personal-tokens/), `:id` with the ID of the edge service and inform the following parameters in the request body:

| Property | Description | Required | 
| - | - | - | 
| `content_type` | Content type of the resource being created | Yes |
| `name` | Name of the resource being created | Yes |
| `content` | Content that defines actions performed when the resource state changes in the edge node | Yes |

:::tip
Check the [Azion API documentation](https://api.azion.com/) and the [OpenAPI specification](https://github.com/aziontech/azionapi-openapi/) to know more about all features available via API.
:::
</Fragment>

</Tabs>

---

## Edge Node variables

<Tabs client:visible>
    <Fragment slot="tab.console">Console</Fragment>
    <Fragment slot="tab.api">API</Fragment>

<Fragment slot="panel.console">
1. Go to [Azion Console](/en/documentation/products/guides/how-to-access-azion-console/).
2. On the top-left corner, select the **Products menu**, represented by three horizontal lines, and then **Edge Nodes**.
3. Select the edge node to which you want to add a variable.
4. Go to the **Services** tab.
5. Choose the [service](/en/documentation/products/guides/deploy/create-edge-service/) to which you want to apply the variable.
6. Add the following content to the variables block: 

```bash 
name=azion2
```

7. Click the **Save** button.

Now, you've created a variable related to a specific node. You need to access this variable through a resource.

1. Go to [Azion Console](/en/documentation/products/guides/how-to-access-azion-console/) > **Edge Services**.
2. Select the service related to the resource. 
3. Click on **+ Resource** or select the resource where you wish to use the variable.
4. Enter the **Path** of the resource.
5. Choose the type **Text**.
6. Add the following content to the content block: 

```bash 
I am using {{name}} Orchestrator
```

7. Click the **Save** button.
</Fragment>

<Fragment slot="panel.api">
1. Run the following `GET` request in your terminal, replacing `[TOKEN VALUE]` with your [personal token](/en/documentation/products/guides/personal-tokens/) and retrieve the edge node ID to which you wish to add a variable:

```bash
curl --location 'https://api.azionapi.net/edge_nodes/' \
--header 'Accept: application/json; version=3' \
--header 'Authorization: Token [TOKEN VALUE]'
```

2. Run the following `GET` request in your terminal, replacing `[TOKEN VALUE]` with your [personal token](/en/documentation/products/guides/personal-tokens/) and `:id` with the ID of the edge node, and retrieve the ID of the relation between the edge node and the chosen service:

```bash
curl --location 'https://api.azionapi.net/edge_nodes/:id/services' \
--header 'Accept: application/json; version=3' \
--header 'Authorization: Token [TOKEN VALUE]'
```

3. Run the following `PATCH` request in your terminal:

```bash
curl --location --request PATCH 'https://api.azionapi.net/edge_nodes/:node_id/services/:bind_id' \
--header 'Accept: application/json; version=3' \
--header 'Authorization: Token [TOKEN VALUE]' \
--data '{
  "variables": [
    {
      "name": "name",
      "value": "Azion"
    }
  ]
}'
```

Replace `[TOKEN VALUE]` with your [personal token](/en/documentation/products/guides/personal-tokens/), `:id` with the ID of the edge node and `:bind_id` with the ID of the relation retrieved in step 2, informing the following properties in the request body:

| Property | Description | Required | 
| - | - | - | 
| `variables` | Variables to be replaced during the processing on the edge node.  | No |

Now, your variables are created and ready to be accessed during the execution on your nodes related to the specific service. It's relevant to stress that when you have a variable with the same name configured on a service and on a node, the value stored on the node will prevail, for example:

Variable configured on the edge service: 

```bash
name=azion
```

Variable configured on the edge node

```bash
name=azion2
```

When the resource is accessed, the value of the variable will be `azion2` instead of `azion`.

To access the resource on the edge node, you need to access the file. You can access it through the filepath you informed during the creation of the resource. 

Resource name: 

```bash
/txt/test
```

To access it: 

```bash 
nano /txt/test
```

:::tip
Check the [Azion API documentation](https://api.azion.com/) and the [OpenAPI specification](https://github.com/aziontech/azionapi-openapi/) to know more about all features available via API.
:::
</Fragment>

</Tabs>