SOLVED: I'm stuck with shell_command

I’m trying to obtain session ID to download station via shell command. Command that works perfectly fine from HA terminal is:

curl 'http://192.168.52.71:8000/webapi/auth.cgi?api=SYNO.API.Auth&version=2&method=login&account=_user_&passwd=_password_&session=DownloadStation&format=sid' > config/sid.json

As expected it logs to Synology NAS, obtains json responce and writes it to sid.json file.
Now I’m trying to move it to shell command:

shell_command:
  get_sds_sid: 'curl ''http://192.168.52.71:8000/webapi/auth.cgi?api=SYNO.API.Auth&version=2&method=login&account=_user_&passwd=_password_&session=DownloadStation&format=sid'' > config/sid.json'

and it does not work… In log file I see error:

2020-08-14 10:43:38 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `curl 'http://192.168.52.71:8000/webapi/auth.cgi?api=SYNO.API.Auth&version=2&method=login&account=_user_&passwd=_password_&session=DownloadStation&format=sid' > config/sid.json`, return code: 1
NoneType: None

I tried all possible (i think) combinations of single and double quotes to wrap this command and url, but always the same result. Any idea what might be wrong?
I know I can use rest sensor for this, but I want to use it in controllable manner. Sensor refreshes at somehow random times, creating race conditions for other depending sensors. Also it refreshes way to frequently to need (changing SID every ~30 seconds instead obtaining it once after HA restart).

You could try:

shell_command:
  get_sds_sid: curl "http://192.168.52.71:8000/webapi/auth.cgi?api=SYNO.API.Auth&version=2&method=login&account=_user_&passwd=_password_&session=DownloadStation&format=sid" > config/sid.json

Thanks @amaximus… already tested such combination and the result is exactly the same…

How about my this one:

platform: command_line
name: get_sds_sid
command: bash -c "curl http://192.168.52.71:8000/webapi/auth.cgi?api=SYNO.API.Auth&version=2&method=login&account=_user_&passwd=_password_&session=DownloadStation&format=sid > config/sid.json"

Didd’t try this previously… so tested and unfortunatelly exactly the same error :frowning:

...return code: 1
NoneType: None

I’m wondering if this might be sort of privledges setup problem? However I added config to whitelist_external_dirs already. What might be the difference between running this command from HA terminal and as a script?

OK, my last shot:

platform: command_line
name: get_sds_sid
command: curl "http://192.168.52.71:8000/webapi/auth.cgi?api=SYNO.API.Auth&version=2&method=login&account=_user_&passwd=_password_&session=DownloadStation&format=sid" > config/sid.json

Sorry to dissapoint… same result :man_facepalming:

@amaximus, I got it working!!!
Turned out to be problem with folders mapping. Command that worked for me is:

shell_command:
  get_sds_sid: 'curl ''http://192.168.52.71:8000/webapi/auth.cgi?api=SYNO.API.Auth&version=2&method=login&account=_user_&passwd=_password_&session=DownloadStation&format=sid'' > sid.json'

or alternatively I discovered that curl -o works as well:

shell_command:
  get_sds_sid: 'curl -o sid.json ''http://192.168.52.71:8000/webapi/auth.cgi?api=SYNO.API.Auth&version=2&method=login&account=_user_&passwd=_password_&session=DownloadStation&format=sid'''

The key was that /config is already root folder for curl command to put output there. So using config/sid.json I was trying to create file in /config/config, which resulted in error, since this subfolder does not existis!

Glad you sorted it out.
I’m also using curl in shell command related sensors and they all worked.