Workflow script with cURL

Hello alltogather

I’d like to send a message like

curl -H "Content-Type: application/json" -X POST -d '{"variables": {"fileName":{"value":"name of the file" } }}' http://192.xxx.xx.xx:8080/xxxxxx

when a file is created or modified in Nextcloud.
I thought to Workflow, and may be a script, but I didn’t see how to manage that curl line.

Additionnal question : how to pass url address of the file ? add %n in variables ?

Thank you for your help.
A

Create a script file, e.g. /var/nextcloud/.scripts/my-curl-script.sh which contains the desired curl command. As usual use $1, $2, $3, ... to access the command line options which you’ve parsed to the script.

The work flow app use the full path to your script and use, e.g. “%n” to parse the relative nc file path, like e.g.:

/var/nextcloud/.scripts/my-curl-script.sh "%n"

Keep in mind that “%n” only contains the relative file path from the Nextcloud data directory, e.g. “/user/files/YourDirectory/20191111_184052.jpg”.

Hi @j-ed

thank you very much for your help. I test it quickly.
regards.

Hello,

I tried following things :

  1. the script line in Nextcloud is : sh /tmp/validDoc.sh
  2. with command line, this script is running well. I’ve the effect forecasted.
  3. I follow the cron process describe cron
  4. cron is running well. I check it : grep CRON /var/log/syslog and obtain : Sep 23 13:55:01 svm CRON[4224]: (www-data) CMD (php -f /var/www/nextcloud/cron.php)
  5. Nevertheless I’ve no effect.

I surely forgot something, but what ? Thank you for your help. Regards.
A

  1. If you create a batch script there is no requirement to call it as a parameter of sh if
  • the first line of the script is "#!/bin/sh"
  • the script has execution rights for the web server user, e.g. “www-data” etc.
  1. Where are you parsing the desired parameter to the script, e.g. “%n” for the file name or “%e” for the event type?

I don’t understand why are you referencing to the cron command now. You initially wrote that you want to execute a curl command?! :confused:

Hello,

thank you for your help @j-ed. I’d a mistake in #!/bin/sh
Why Cron : for what I’ve unbderstood, we need cron to launch /var/www/nextcloud/cron.php? Isn’t it ?

Yes as described in the administrator guide, but this is a different story, isn’t it? The subject of this thread is “Workflow script with cURL” and not “cron.php”?! You should try not to mix-up different things in one thread.

Hi,
thank for your clarification.
A