Unoffical danalock web API

Hi!

Try to debug (add a bunch of debug nodes) the Oauth2 subflow & trigger the flow (i.e. by pasting the URL in a browser):

image

@ruzzbug sorry, but what NR item did you change urls in? I’ve tried adding debuts to everything but don’t really understand the ins and outs. I still keep getting 401 in debug logs

@gechu this might seem like a silly question, but the 2 yaml files on your github ( unofficial-danabridge-web-api.yaml and unofficial-danalock-web-api.yaml) - is this supposed to be added to HA somehow for everything else to work? If so, how do I go about adding that?

It was a while ago now so I don´t really remember. But this i what the switch node look like:

image

And the www request node:

image

You should be able to get the lock status by entering this url in a web-browser:
http://node-red-host:1880/endpoint/danalock/bridge/v1/execute/status

Can you see the lock status if you log in to “My Danalock”:
https://my.danalock.com/#/login

Thanks. I can see the lock status when in the website. Will have a look at the NR flow again

@Townsmcp, there are no silly questions :wink:

Those files are in yaml, and shaped according to the OpenApi specification = a way to describe web apis. This standard use to be called Swagger. You don’t need them in HA, but looking into them, you could build the entire nodered implementation on your own.

Still coming up stumped :frowning:
Any chance you can publish your NR flow?

hmmmm well this is interesting. I have recently started a new HA build on ProxMox and have installed a seperate instance of NR in its own LXC.
I have just imported the script into the new NodeRed and installed contrib-oauth2 (and the HA pallette). I have populated the username and password in the correct nodes and now, when I run the inject, I actually get a token back rather than error 400/401.
In debug, I am seeing the following error though:


When hovering over the error it is highlighting the ‘Set Flow Context’ function - any ideas how to resolve?

I seem to be stuck at this exact same step. Where you able to get past this stage? Is there any specific Node Red version and Node Red wrapper that is verified to work?

Hi guys, not sure I can help, but the error message seems to be related to this code in the “set context” node:

msg.headers = {};

flow.set("$parent.refresh_token", msg.payload.oauth2Response.body.refresh_token);
flow.set("$parent.access_token",  msg.payload.oauth2Response.body.access_token);

return msg;

One potential reason why you get this error may be because the Oauth node didn’t work - since it’s not possible to set msg.payload.oauth2Response.body

I suggest that you add more debug nodes along the flow and share the output - just remember to remove your password.

To check the status of the lock I use this command

GET home-assistant-host:1880/danalock/bridge/v1/execute/status

Did you change the basepath back when you installed nodered in a lxc container (proxmox)?

In my set up, the Oauth node doesn`t seem to take the credentials. Even when they are configured in the “Set Danalock user credentials” node.

Can you show the code where you set the username and password? Don’t forget to change them to dummy values, but keep the format.

Not really sure where to get the actual code. This is the debug message from the first debug node that i placed in the OAuth flow:

{"_msgid":"47e66b70cdd7dfc7","headers":{"access-control-allow-credentials":"true","access-control-allow-headers":"Content-Type, Authorization, X-Assume-User","access-control-allow-methods":"GET, POST, DELETE, PUT, PATCH, HEAD","access-control-allow-origin":"*","access-control-expose-headers":"X-Page, X-Pages, X-PerPage, X-TotalRecords, mode","cache-control":"no-cache, no-store, must-revalidate","content-type":"application/json","date":"Thu, 21 Oct 2021 21:02:06 GMT","expires":"0","server":"nginx","vary":"Origin","content-length":"48","connection":"Close","x-node-red-request-node":"216b73d9"},"method":"GET","url":"https://api.danalock.com/locks/v1","statusCode":401,"responseUrl":"https://api.danalock.com/locks/v1","redirectList":[],"retry":0,"req":{"_readableState":{"objectMode":false,"highWaterMark":16384,"buffer":{"head":null,"tail":null,"length":0},"length":0,"pipes":[],"flowing":null,"ended":true,"endEmitted":false,"reading":false,"sync":true,"needReadable":false,"emittedReadable":false,"readableListening":false,"resumeScheduled":false,"errorEmitted":false,"emitClose":true,"autoDestroy":false,"destroyed":false,"errored":null,"closed":false,"closeEmitted":false,"defaultEncoding":"utf8","awaitDrainWriters":null,"multiAwaitDrain":false,"readingMore":true,"decoder":null,"encoding":null},"_events":{},"_eventsCount":1,"socket":"[internal]","httpVersionMajor":1,"httpVersionMinor":1,"httpVersion":"1.1","complete":true,"headers":{"host":"192.168.1.123:1880","connection":"keep-alive","upgrade-insecure-requests":"1","user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36","accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9","accept-encoding":"gzip, deflate","accept-language":"nb-NO,nb;q=0.9,no;q=0.8,nn;q=0.7,en-US;q=0.6,en;q=0.5"},"rawHeaders":["Host","192.168.1.123:1880","Connection","keep-alive","Upgrade-Insecure-Requests","1","User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36","Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9","Accept-Encoding","gzip, deflate","Accept-Language","nb-NO,nb;q=0.9,no;q=0.8,nn;q=0.7,en-US;q=0.6,en;q=0.5"],"trailers":{},"rawTrailers":[],"aborted":false,"upgrade":false,"url":"/danalock/bridge/v1/execute/status","method":"GET","statusCode":null,"statusMessage":null,"client":"[internal]","_consuming":false,"_dumped":false,"baseUrl":"","originalUrl":"/danalock/bridge/v1/execute/status","_parsedUrl":{"protocol":null,"slashes":null,"auth":null,"host":null,"port":null,"hostname":null,"hash":null,"search":null,"query":null,"pathname":"/danalock/bridge/v1/execute/status","path":"/danalock/bridge/v1/execute/status","href":"/danalock/bridge/v1/execute/status","_raw":"/danalock/bridge/v1/execute/status"},"params":{"0":"bridge/v1/execute/status"},"query":{},"res":"[internal]","body":{},"_parsedOriginalUrl":{"protocol":null,"slashes":null,"auth":null,"host":null,"port":null,"hostname":null,"hash":null,"search":null,"query":null,"pathname":"/danalock/bridge/v1/execute/status","path":"/danalock/bridge/v1/execute/status","href":"/danalock/bridge/v1/execute/status","_raw":"/danalock/bridge/v1/execute/status"},"route":{"path":"/danalock/*","stack":[{"name":"cookieParser","keys":[],"regexp":{"fast_star":false,"fast_slash":false},"method":"get"},{"name":"httpMiddleware","keys":[],"regexp":{"fast_star":false,"fast_slash":false},"method":"get"},{"name":"corsHandler","keys":[],"regexp":{"fast_star":false,"fast_slash":false},"method":"get"},{"name":"metricsHandler","keys":[],"regexp":{"fast_star":false,"fast_slash":false},"method":"get"},{"name":"<anonymous>","keys":[],"regexp":{"fast_star":false,"fast_slash":false},"method":"get"},{"name":"<anonymous>","keys":[],"regexp":{"fast_star":false,"fast_slash":false},"method":"get"}],"methods":{"get":true}},"cookies":{},"signedCookies":{}},"res":{}}

This is where I set the credentials:

Now let’s see what happens with these flow variables (username, password) .

Try this node-red-contrib-contextbrowser (node) - Node-RED

What did you learn?

The contextbrowser seems to display the correct content of the variables:

{"access_token":"need-to-refresh","danalock-password":"correct-password","danalock-username":"correct-username"}

Do you have a working setup that you can share? Any specific node-red version? My install is the latest docker-image that is v2.0.6

I use version 1.2.9, and the code in github AS-IS, running in a proxmox Ubuntu 20.04 container.

I’ll look into migrating it to v2 of node red. Perhaps there’s a change that prevents the code on your system from working properly.

Was worth a shot, but got the exact same behaviour with a fresh install of v1.2.9, and the node-red wrapper code from github.

Hi - just to add that I havre exactly the same issue…

Good news! I can reproduce the issue. I’ll start working on it later this week :slight_smile: :+1:

Done! Please try out the updated flow. Note that I haven’t tried it out much myself.