# Something wrong with API call to set tags

**URL:** <https://hub.mender.io/t/something-wrong-with-api-call-to-set-tags/5902>\
**Category:** General Discussions\
**Created:** [June 7, 2023, 12:51pm UTC](https://hub.mender.io/t/something-wrong-with-api-call-to-set-tags/5902 "2023-06-07T12:51:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mister\_kanister](https://avatars.discourse-cdn.com/v4/letter/m/8edcca/32.png) [@mister\_kanister](https://hub.mender.io/u/mister_kanister)\
**Post date:** [June 7, 2023, 12:51pm UTC](https://hub.mender.io/t/something-wrong-with-api-call-to-set-tags/5902/1 "2023-06-07T12:51:58Z")

</div>

Hello friends!  
I have a preauthorized device that was never online. After the preauthorization I try to apply tags via API call but I get different errors and can’t figure out what wrong. I use Python with hosted Mender 3.4. Some other calls like “get\_artifact\_id(artifact\_name)” are working.

```auto
    def apply_tags(self, radxa):        
        headers = {
            'Content-Type': 'application/json',
            'Accept': 'application/json',
            'If-Match': 'string',
            'Authorization': f'Bearer {self.pat}'
        }
        # radxa.device_id = "699d6cb2-d461-4288-8739-08c8173e7226"
        endpoint = f"/api/management/v1/inventory/devices/{radxa.device_id}/tags"
        # Static payload for debugging
        tag = "[{'name': 'customtag', 'value':'value'}]"
        response = requests.patch(self.server_uri + endpoint, headers=headers, json=tag)

        if response.status_code == 200:
            print(f"Tags added for {radxa.device_id}:")
            print(radxa.tags)
        else:
            print(f"[Error]: Could not apply tags to device {radxa.device_id}")
            print("HTTP response:", response.status_code)
            print(response.text)
            print(response.reason)

```

This call produces the error

```auto
[Error]: Could not apply tags to device 699d6cb2-d461-4288-8739-08c8173e7226
HTTP response: 400
{"error":"failed to decode request body: json: cannot unmarshal string into Go value of type []model.DeviceAttribute","request_id":"cfeb5eee-70ec-4a40-ab74-b9531b6d34ee"}
Bad Request

```

Other error if pass in only one object not within an array

```auto
HTTP response: 412
{"error":"ETag does not match","request_id":"08895124-92c6-42ee-b8d6-fc1b396f5966"}
Precondition Failed

```

If pass in a Python list with Python dicts in it. This is crazy.

```auto
HTTP response: 400
{"error":"failed to decode request body: invalid character 'a' in literal null (expecting 'u')","request_id":"06930d8f-a6f3-4076-9a20-108e362b7f21"}

```

I tried also to covert to JSON string from Python list with dictionaries resulting in same error.

```auto
json_tags = [
    {
      "name":"my_tag_name",
       "value": "my_value",
     }
]
json_tags = json.dumps(json_tags)

```

I have similar calls constructed and they worked if I passed `json=python_dict`. This is somehow inconsisten.
