Synology API Auth login

This is an example how to authenticate and get the token/security identifier for any further Synology API calls. The main inputs are the account and passwd, and the url for the Synology.
The security identifier and url for further API requests are saved as flow variables.
Check the Synology API Collection for related examples.

http requestinjectsave sidLogin requestRequest token using SYNO.API.Authdebug 68
Flow 1
[{"id":"8aa55e266ba632b3","type":"group","z":"55979001e6fb4b69","style":{"stroke":"#999999","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["56e4d38c48aacc92","be7703250d7ddf97","d0e4714f3eaa0ba0","99823cbcf8373d34","f32d04c276ea1f55","c9e532a58f329643"],"x":34,"y":39,"w":972,"h":142},{"id":"56e4d38c48aacc92","type":"http request","z":"55979001e6fb4b69","g":"8aa55e266ba632b3","name":"","method":"use","ret":"obj","paytoqs":"query","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":530,"y":140,"wires":[["d0e4714f3eaa0ba0"]]},{"id":"be7703250d7ddf97","type":"inject","z":"55979001e6fb4b69","g":"8aa55e266ba632b3","name":"","props":[{"p":"account","v":"myaccount","vt":"str"},{"p":"passwd","v":"mypasswd","vt":"str"},{"p":"session","v":"mysession","vt":"str"},{"p":"baseurl","v":"https://mysynology:5001/","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":130,"y":140,"wires":[["99823cbcf8373d34"]]},{"id":"d0e4714f3eaa0ba0","type":"function","z":"55979001e6fb4b69","g":"8aa55e266ba632b3","name":"save sid","func":"node.status({ \n    fill: msg.payload.success ? \"green\" : \"red\", \n    shape: \"ring\", \n    text: msg.payload.success ? msg.payload.data.synotoken : \"failed\" \n});\n\nflow.set(\"sid\", msg.payload.data.sid); // Authorized session ID.\nflow.set(\"synotoken\", msg.payload.data.synotoken); // (Optional) This token avoids Cross-Site Request Forgery.\nflow.set(\"device_id\", msg.payload.data.device_id); // A.k.a. device id, to identify which device.\n\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":720,"y":140,"wires":[["c9e532a58f329643"]]},{"id":"99823cbcf8373d34","type":"function","z":"55979001e6fb4b69","g":"8aa55e266ba632b3","name":"Login request","func":"/*\nINPUT\n  msg.account  Login account name\n  msg.passwd   Login account password\n  msg.session  (Optional) Login session name for DSM Applications\n  msg.baseurl 'https://mysynology:port/'\n*/\n\nflow.set(\"synoentryurl\", msg.baseurl + \"webapi/entry.cgi\");\n\nmsg.method = \"GET\";\nmsg.url = msg.baseurl + \"webapi/auth.cgi\";\nmsg.payload = {\n    \"api\": \"SYNO.API.Auth\",\n    \"version\": 7,\n    \"method\": \"login\",\n    \"account\": msg.account,\n    \"passwd\": msg.passwd,\n    \"session\": msg.session,\n    \"format\": \"sid\",\n    \"enable_syno_token\": \"yes\"\n}\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":140,"wires":[["56e4d38c48aacc92"]]},{"id":"f32d04c276ea1f55","type":"comment","z":"55979001e6fb4b69","g":"8aa55e266ba632b3","name":"Request token using SYNO.API.Auth","info":"","x":200,"y":80,"wires":[]},{"id":"c9e532a58f329643","type":"debug","z":"55979001e6fb4b69","g":"8aa55e266ba632b3","name":"debug 68","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":900,"y":140,"wires":[]}]

Flow Info

Created 11 months, 1 week ago
Rating: not yet rated

Owner

Actions

Node Types

Core
  • comment (x1)
  • debug (x1)
  • function (x2)
  • http request (x1)
  • inject (x1)
Other

Tags

  • Synology
  • API
  • SYNO.API.Auth
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option