OpenWonderLabs / SwitchBotAPI

SwitchBot Open API Documents
863 stars 71 forks source link

Lockoing/unlocking Lock pro via API is not working #317

Closed ric-101 closed 3 weeks ago

ric-101 commented 3 months ago

Lock Pro API 400 Error for no apparent reason

Hi there!

So I'm trying to control my SwitchBot Lock Pro via API (through the hub, of course).

I can correctly connect to the hub, and query the Lock Pro via API (get status of the LockPro), but as I try to Lock/Unlock it I keep getting an error.

But when I try and run it, I get the following error: "One or more parameter values are not valid. The AttributeValue for a key attribute cannot contain an empty string value. Key: sn" - but I have no clue what "sn" is nor where it should be (I tried added it in the payload and the header, with no success).

Attached is a screenshot of my (python) code, and the result when trying to run it:

image

Anyone can help?

Thank you!!

Logs

b'{"statusCode":400,"body":{},"message":"One or more parameter values are not valid. The AttributeValue for a key attribute cannot contain an empty string value. Key: sn"}'

Configuration

noting useful

Environment

Additional Context

No response

hsakoh commented 3 months ago

I don't really understand Python syntax, but does the payload include parameter=default and commandType=command?

hsakoh commented 3 months ago

I am testing with the Lock, not the Lock Pro, and both payloads worked fine.

{"commandType":"command","command":"lock","parameter":"default"}
{"command":"lock"}

It seems that something else is causing the issue.

ric-101 commented 3 months ago

Thank you! Yeas I tried both, and the results are the exact same, I guess "commandType"and "command" get ignored... let's see if anyone at SwitchBot can help!

donavanbecker commented 3 months ago

Just tested this on a Lock Pro on the Homebridge-SwitchBot plugin and works just fine.

ric-101 commented 3 months ago

Just tested this on a Lock Pro on the Homebridge-SwitchBot plugin and works just fine.

Hi Donavan, thank you for trying. I agree it should work 😅 but unfortunately it doesn't for me, I keep getting the same error... I tried updating firmware on both the Hub and the Lock Pro but still nothing changed.... I see you're marked as "collaborator", any chance you could look up what could cause that specific error? (I couldn't find anything online nor on the documentation), anything else I could try?

Cheers :)

donavanbecker commented 3 months ago

I don't work for SwitchBot just maintain the Homebridge plugin. It is clearly something that you are not doing correctly. I have no problems with the plugin control the Lock Pro

ric-101 commented 3 months ago

I don't work for SwitchBot just maintain the Homebridge plugin. It is clearly something that you are not doing correctly. I have no problems with the plugin control the Lock Pro

Thank you!

Yeah, I'm definitely doing something wrong, but haven;t been able to figure out what it is. It should be a simple API call, shouldn't it? Once I don't get an authentication error and the payload is correct, what else could go wrong? (and the payload here should be super simple). The error message isn't helping at all, either..

I'm using the "Hub Mini2", in case it makes any difference.

By the way, I noticed that I can access it from a remote network too, does the Hub connect to a SwitchBot's public server? Is there a way to make it only accessible locally, without internet access?

Thank you :)

ric-101 commented 3 months ago

Keep getting the same error ("One or more parameter values are not valid. The AttributeValue for a key attribute cannot contain an empty string value. Key: sn"), anyone else might help? @SwitchBot-Wonderlabs , @SwitchBot?

Thank you :)

ric-101 commented 3 months ago

omebridge-SwitchBot plugin

Do I need to install the plug-in in order to use the API? If so, could you explain a little more, or link a guide which explains how this works?

Thanks for your help!!

donavanbecker commented 3 months ago

no you don't need to install the plugin, but you are missing something, but I am not sure what.

ric-101 commented 3 weeks ago

Solved with firmware update