# HTTP 500 on set capability via rest API

**URL:** <https://community.homey.app/t/http-500-on-set-capability-via-rest-api/75579>\
**Category:** Developers\
**Created:** [January 25, 2023, 5:39pm UTC](https://community.homey.app/t/http-500-on-set-capability-via-rest-api/75579 "2023-01-25T17:39:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fvrdam](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/fvrdam/32/47643_2.png) [@fvrdam](https://community.homey.app/u/fvrdam)\
**Post date:** [January 25, 2023, 5:39pm UTC](https://community.homey.app/t/http-500-on-set-capability-via-rest-api/75579/1 "2023-01-25T17:39:01Z")

</div>

I’m writing python code to interact with Homey through the oauth web API.  
All works up to the point where I want tot set a value for a device.

```auto
  def set_target_temp(self, ts, temp):
        if self.use_bearer():
            id = self.get_device_id(ts)
            url = 'http://192.168.1.93/api/manager/devices/device/'+id+'/capability/target_temperature/'  
            headr = {'Authorization': 'Bearer ' + self.bearer_token}
            put_data = { "value": 13.0 }
            response = requests.put(url=url, data=put_data, headers=headr)
            if (response.status_code != 200):
                return {"status": "failed"}
            else:
                return {"status": "ok"}

```

This return an HTTP 500 with:

```auto
{
	"code": 500,
	"error": "target_temperature InvalidTypeError: 13.0 is of type string but expected number (invalid_type)",
	"error_description": "target_temperature InvalidTypeError: 13.0 is of type string but expected number (invalid_type)"
}

```

I also tried { “value”: “13” } with the same result.  
Anyone ran into this before?

Frank

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [January 25, 2023, 6:44pm UTC](https://community.homey.app/t/http-500-on-set-capability-via-rest-api/75579/2 "2023-01-25T18:44:33Z")

</div>

Are you sure that `requests` is:

- posting the data as JSON
- setting the correct content-type (`application/json`)?

It looks to me like it might be sending the data as `application/x-www-form-urlencoded`, which is typeless and therefore will always be interpreted as string.

---

<div class="post-metadata">

**Author:** ![fvrdam](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/fvrdam/32/47643_2.png) [@fvrdam](https://community.homey.app/u/fvrdam)\
**Post date:** [January 25, 2023, 6:47pm UTC](https://community.homey.app/t/http-500-on-set-capability-via-rest-api/75579/3 "2023-01-25T18:47:43Z")

</div>

Spot on as usual, thanks Robert !  
I’ve changed to json=put\_data and this works:

````auto
    def set_target_temp(self, ts, temp):
        if self.use_bearer():
            id = self.get_device_id(ts)
            url = 'http://192.168.1.93/api/manager/devices/device/'+id+'/capability/target_temperature/' # getFirstHomey
            headr = {'Authorization': 'Bearer ' + self.bearer_token}
            put_data = { "value": 13.0 }
            response = requests.put(url=url, json=put_data, headers=headr)
            if (response.status_code != 200): #do we need this ?
                return {"status": "failed"}
            else:
                return {"status": "ok"}```
````
