# Device service variable

## Get all service variables for a device by UUID

> \## Device service variable Resource Fields\
> \
> \| Field |\
> \| :--- |\
> \| \`id\` |\
> \| \`created\_at\` |\
> \| \`service\_install\` |\
> \| \`value\` |\
> \| \`name\` |\
> \
> \
> \---\
> \
> \`GET /v7/device\_service\_environment\_variable\`\
> \
> \
> \### Usage Variations\
> \
> \--- \
> \#### Get all service variables for a device by UUID, including the service name\
> \`GET /v7/device\_service\_environment\_variable?$filter=service\_install/any(si:si/device/any(d:d/uuid eq '\<DEVICE\_UUID>'))&$expand=service\_install($expand=installs\_\_service($select=id,service\_name))\`\
> \
> \--- \
> \#### Get all service variables for a device by ID\
> \`GET /v7/device\_service\_environment\_variable?$filter=service\_install/device eq \<DEVICE ID>\`

```json
{"openapi":"3.0.0","info":{"title":"Balena API Spec","version":"7.0.0"},"servers":[{"url":"https://api.balena-cloud.com"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer"}}},"paths":{"/v7/device_service_environment_variable":{"get":{"tags":["Device service variable"],"summary":"Get all service variables for a device by UUID","description":"## Device service variable Resource Fields\n\n| Field |\n| :--- |\n| `id` |\n| `created_at` |\n| `service_install` |\n| `value` |\n| `name` |\n\n\n---\n\n`GET /v7/device_service_environment_variable`\n\n\n### Usage Variations\n\n--- \n#### Get all service variables for a device by UUID, including the service name\n`GET /v7/device_service_environment_variable?$filter=service_install/any(si:si/device/any(d:d/uuid eq '<DEVICE_UUID>'))&$expand=service_install($expand=installs__service($select=id,service_name))`\n\n--- \n#### Get all service variables for a device by ID\n`GET /v7/device_service_environment_variable?$filter=service_install/device eq <DEVICE ID>`"}}}}
```

## Create a device service variable

> \`POST /v7/device\_service\_environment\_variable\`\
> \
> \*\*Request Body:\*\*\
> \`\`\`json\
> {\
> &#x20;   "service\_install": \<SERVICE INSTALL ID>,\
> &#x20;   "name": \<NAME>,\
> &#x20;   "value": \<VALUE>\
> }\
> \`\`\`

````json
{"openapi":"3.0.0","info":{"title":"Balena API Spec","version":"7.0.0"},"servers":[{"url":"https://api.balena-cloud.com"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer"}}},"paths":{"/v7/device_service_environment_variable":{"post":{"tags":["Device service variable"],"summary":"Create a device service variable","description":"`POST /v7/device_service_environment_variable`\n\n**Request Body:**\n```json\n{\n    \"service_install\": <SERVICE INSTALL ID>,\n    \"name\": <NAME>,\n    \"value\": <VALUE>\n}\n```","requestBody":{"content":{"application/json":{"schema":{"type":"object"}}}}}}}}
````

## Remove a device service variable

> \`DELETE /v7/device\_service\_environment\_variable(\<ID>)\`

```json
{"openapi":"3.0.0","info":{"title":"Balena API Spec","version":"7.0.0"},"servers":[{"url":"https://api.balena-cloud.com"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer"}}},"paths":{"/v7/device_service_environment_variable({ID})":{"delete":{"tags":["Device service variable"],"summary":"Remove a device service variable","description":"`DELETE /v7/device_service_environment_variable(<ID>)`","parameters":[{"name":"ID","in":"path","required":true}]}}}}
```

## Update a device service variable

> \`PATCH /v7/device\_service\_environment\_variable(\<ID>)\`\
> \
> \*\*Request Body:\*\*\
> \`\`\`json\
> {\
> &#x20;   "value": \<NEW VALUE>\
> }\
> \`\`\`

````json
{"openapi":"3.0.0","info":{"title":"Balena API Spec","version":"7.0.0"},"servers":[{"url":"https://api.balena-cloud.com"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer"}}},"paths":{"/v7/device_service_environment_variable({ID})":{"patch":{"tags":["Device service variable"],"summary":"Update a device service variable","description":"`PATCH /v7/device_service_environment_variable(<ID>)`\n\n**Request Body:**\n```json\n{\n    \"value\": <NEW VALUE>\n}\n```","parameters":[{"name":"ID","in":"path","required":true}],"requestBody":{"content":{"application/json":{"schema":{"type":"object"}}}}}}}}
````
