> For the complete documentation index, see [llms.txt](https://docs.balena.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.balena.io/reference/api/resources/device_service_environment_variable.md).

# Device service variable

## Available Fields

| Field             |
| ----------------- |
| `id`              |
| `created_at`      |
| `service_install` |
| `value`           |
| `name`            |

***

## Examples

### Get all service variables for a device by UUID

```bash
GET "https://api.balena-cloud.com/v7/device_service_environment_variable?\$filter=service_install/any(si:si/device/any(d:d/uuid%20eq%20'<DEVICE_UUID>'))" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <AUTH_TOKEN>" 
```

### Get all service variables for a device by UUID, including the service name

```bash
GET "https://api.balena-cloud.com/v7/device_service_environment_variable?\$filter=service_install/any(si:si/device/any(d:d/uuid%20eq%20'<DEVICE_UUID>'))&\$expand=service_install(\$expand=installs__service(\$select=id,service_name))" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <AUTH_TOKEN>" 
```

### Get all service variables for a device by ID

```bash
GET "https://api.balena-cloud.com/v7/device_service_environment_variable?\$filter=service_install/device%20eq%20<DEVICE ID>" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <AUTH_TOKEN>" 
```

### Create a device service variable

```bash
POST "https://api.balena-cloud.com/v7/device_service_environment_variable" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <AUTH_TOKEN>" \
--data '{
    "service_install": "<SERVICE INSTALL ID>",
    "name": "<NAME>",
    "value": "<VALUE>"
}'
```

### Update a device service variable

```bash
PATCH "https://api.balena-cloud.com/v7/device_service_environment_variable(<ID>)" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <AUTH_TOKEN>" \
--data '{
    "value": "<NEW VALUE>"
}'
```

### Remove a device service variable

```bash
DELETE "https://api.balena-cloud.com/v7/device_service_environment_variable(<ID>)" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <AUTH_TOKEN>" 
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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.balena.io/reference/api/resources/device_service_environment_variable.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.
