OpenWonderLabs / SwitchBotAPI

SwitchBot Open API Documents
810 stars 68 forks source link

``/v1.0/devices/`` endpoint - device list functionality errored #307

Open ThatProgrammerr opened 1 month ago

ThatProgrammerr commented 1 month ago

Analysis

Suddenly I can't get a list of devices at https://api.switch-bot.com/v1.0/devices/ - I have had an existing piece of software using this endpoint fine for over a month and suddenly it just sends this, killing my ability to pull dynamic data. I am still able to use the same endpoint with the device id to get that sensors' data, but dynamically grabbing that data via a device list is no-longer possible.

{
  "statusCode": 190,
  "body": { },
  "message": "Cannot read properties of undefined (reading 'device_type')"
}

Expected Behavior

Provides a list of devices in json format

Steps To Reproduce

Visit https://api.switch-bot.com/v1.0/devices/ with your valid Authorization header.

Logs

{'statusCode': 190, 'body': {}, 'message': "Cannot read properties of undefined (reading 'device_type')"}

Configuration

N/A

Environment

Issue also possible in browser, unrelated to any of the below.

Additional Context

I believe this is an issue on the API side, likely caused by a misconfiguration. Unless somehow the endpoint was recently deprecated.

ThatProgrammerr commented 1 month ago

I have manually worked around this endpoint not working by manually defining all the IDs and Names of my sensors in my code and hitting https://api.switch-bot.com/v1.0/devices/{device_id}/status directly, rather than grabbing a list of devices and picking them out by name to get the data. I hope this is fixed soon, but my code can continue to run for now, thankfully.

donavanbecker commented 1 month ago

@ThatProgrammerr have you tried using version 1.1 of the API?

ThatProgrammerr commented 1 month ago

https://api.switch-bot.com/v1.0/devices/

@ThatProgrammerr have you tried using version 1.1 of the API?

My key from the Switchbot app doesn't work on the 1.1 api.

donavanbecker commented 1 month ago

https://api.switch-bot.com/v1.0/devices/

@ThatProgrammerr have you tried using version 1.1 of the API?

My key from the Switchbot app doesn't work on the 1.1 api.

Have you tried regenerating it?

Sounds like something you have to reach out to Switchbot Support on.

richsimpson commented 1 month ago

found similar issue. Working fine for over a year then an error Tried to regenerate a new token, using that with v1.0 API I get the 190 error when listing devices. When trying with the 1.1 API I get unauthorized.

The token is right though, if I change the last digit then v1.0 API also says unauthorized. So its the right token. Weird, hopefully fix itself in the next few days. Surprised there is so little noise about it. I only have original lock and virtual infrared remote buttons setup.

ThatProgrammerr commented 3 weeks ago

This still appears to be down. I'm still using my workaround. Oddly enough, it seems like the Switchbot Cloud integration for Home Assistant - unsure how - manages to bypass this endpoint and still retrieve a device list. I can only assume using some other endpoint.

ThatProgrammerr commented 3 weeks ago

https://api.switch-bot.com/v1.0/devices/

@ThatProgrammerr have you tried using version 1.1 of the API?

My key from the Switchbot app doesn't work on the 1.1 api.

Turns out I was mistaken when I said this. I was only trying to use the 1.1 endpoint with my web browser and the auth header, as was previously possible. It seems adjusting my current code to use the 1.1 endpoint does resolve the issue. So that explains how the cloud addon for HA works. I will likely hold a cache of my device ids in case this endpoint dies again and save it to a file to avoid losing cache in the event I restart the program. I'm not aware how long 1.1 has been out, but it would have been nice to get some notice that 1.0 was going to be crippled a little bit.

ioprogram commented 2 weeks ago

Hi! I've the same problem for my application. Is there another way to get a device id? I did not find it in app.