# Balena device tag PATCH updates all tags

**URL:** <https://forums.balena.io/t/balena-device-tag-patch-updates-all-tags/6183>\
**Category:** Product support\
**Created:** [April 22, 2019, 8:11pm UTC](https://forums.balena.io/t/balena-device-tag-patch-updates-all-tags/6183 "2019-04-22T20:11:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicktardif](https://avatars.discourse-cdn.com/v4/letter/n/0ea827/32.png) [@nicktardif](https://forums.balena.io/u/nicktardif)\
**Post date:** [April 22, 2019, 8:11pm UTC](https://forums.balena.io/t/balena-device-tag-patch-updates-all-tags/6183/1 "2019-04-22T20:11:20Z")

</div>

Hi, I think I found a bug with the Balena Device Tag API. If we update a tag using the PATCH HTTP method, it looks like all the tags on that device get set to the new value, instead of only updating the tag with the specified key.

Here’s a quick script that triggers the issue:

```bash
API_TOKEN=<YOUR_TOKEN>
DEVICE_ID=<YOUR_DEVICE_ID>
curl -X POST "https://api.balena-cloud.com/v4/device_tag" -H "Content-Type: application/json" -H "Authorization: Bearer ${API_TOKEN}" --data '{ "device": '${DEVICE_ID}', "tag_key": "tag1", "value": "value1" }'
curl -X POST "https://api.balena-cloud.com/v4/device_tag" -H "Content-Type: application/json" -H "Authorization: Bearer ${API_TOKEN}" --data '{ "device": '${DEVICE_ID}', "tag_key": "tag2", "value": "value2" }'
curl -X POST "https://api.balena-cloud.com/v4/device_tag" -H "Content-Type: application/json" -H "Authorization: Bearer ${API_TOKEN}" --data '{ "device": '${DEVICE_ID}', "tag_key": "tag3", "value": "value3" }'
curl -X PATCH "https://api.balena-cloud.com/v4/device_tag" -H "Content-Type: application/json" -H "Authorization: Bearer ${API_TOKEN}" --data '{ "device": '${DEVICE_ID}', "tag_key": "tag3", "value": "new_value3" }'

```

---

<div class="post-metadata">

**Author:** ![shaunmulligan](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/shaunmulligan/32/34_2.png) [@shaunmulligan](https://forums.balena.io/u/shaunmulligan)\
**Post date:** [April 23, 2019, 3:55pm UTC](https://forums.balena.io/t/balena-device-tag-patch-updates-all-tags/6183/3 "2019-04-23T15:55:41Z")

</div>

Hi @nicktardif, thanks for the report. I reproduced it on my side and I’m chasing up the bug with our API engineers. I will follow up here once I know now.

---

<div class="post-metadata">

**Author:** ![thgreasi](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/thgreasi/32/454_2.png) [@thgreasi](https://forums.balena.io/u/thgreasi)\
**Post date:** [April 23, 2019, 4:12pm UTC](https://forums.balena.io/t/balena-device-tag-patch-updates-all-tags/6183/4 "2019-04-23T16:12:41Z")

</div>

Hi @nicktardif,  
It seems that the PATCH cURL that you provided isn’t doing an OData filter and that’s why all device tags were affected.  
Here is a PATCH cURL that updates the tag value of a tag with a specific key and of a specific device

```bash
API_TOKEN=<YOUR_TOKEN>
DEVICE_ID=<YOUR_TARGET_DEVICE_ID>
TAG_KEY=<YOUR_TARGET_TAG_KEY>
curl "https://api.balena-cloud.com/v5/device_tag?\$filter=(device%20eq%20$DEVICE_ID)%20and%20(tag_key%20eq%20%27$TAG_KEY%27)" -X PATCH -H "Authorization: Bearer ${API_TOKEN}" -H 'content-type: application/json' --data-binary '{"value":"new_value3"}'

```

---

<div class="post-metadata">

**Author:** ![nicktardif](https://avatars.discourse-cdn.com/v4/letter/n/0ea827/32.png) [@nicktardif](https://forums.balena.io/u/nicktardif)\
**Post date:** [April 23, 2019, 6:01pm UTC](https://forums.balena.io/t/balena-device-tag-patch-updates-all-tags/6183/5 "2019-04-23T18:01:34Z")

</div>

Cool that worked, thank you @shaunmulligan and @thgreasi !

---

<div class="post-metadata">

**Author:** ![Alejoxbg](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@Alejoxbg](https://forums.balena.io/u/Alejoxbg)\
**Post date:** [January 17, 2022, 6:44pm UTC](https://forums.balena.io/t/balena-device-tag-patch-updates-all-tags/6183/6 "2022-01-17T18:44:26Z")

</div>

Here is a solution that works with the current version V6

```auto
curl -X PATCH \
"https://api.balena-cloud.com/v6/device_tag?\$filter=device/uuid%20eq%20'<UUID>'%20and%20tag_key%20eq%20'<TAG_KEY>'" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <AUTH_TOKEN>" \
--data '{
    "value": "<NEW-VALUE>"
}'

```
