Using curl to insert an event into a calendar


I am writing a command line script to put events into a calendar using curl. I managed to get this working by first creating a temporary local calendar file and then uploading this file to the server using these commands:

$command > $localfile
curl -T "$localfile" $url

This works perfectly, but I’d like to get rid of the local file. I’m looking for a way to pipe the output of $command straight to curl. Something like this:

$command | curl -T - $url

According to curl’s manual, the option T - should be what is required: read from stdin instead from a file. But if I use that option, I get this response:

  <?xml version="1.0" encoding="utf-8"?>
    <d:error xmlns:d="DAV:" xmlns:s="">
      <s:message>PUT is not allowed on non-files.</s:message>

Does any one know how to do this?

I’m not very experienced with cURL but -T (--upload-file) will try to upload the file. You’ll probably need to use --data or other parameters like --data-raw.
I’m afraid I cannot help you in detail, but maybe this solves it or is at least a hint in the right direction.

As this is more a cURL/Linux and not a specific Nextcloud question, you might get better answers on sites like stackoverflow.

Yes and no. :slight_smile:

I was thinking this could also be an issue specific to NC, maybe NC needs a special parameter or some option in the server’s settings to allow this kind of upload.

Try this one: $command | curl --data @- $url
If it doesn’t work try --data-raw or --data-urlencode parameters instead.

EDIT: Or maybe $command | curl -T . $url

And of course a very simple workaround if you want to get rid of the local file (but using it temporarily) would look like this:
curl -T "$localfile" $url && rm $localfile

@weka don’t know if is helpful for you to generate the correct curl command.

grafik -> grafik

@weka have you solved that problem and are you maybe able to share your solution/the script?

Ups! Sorry, I completely forgot… :flushed:

Yes , I was able to solve the problem by using a HERE-document:

RNDUID=$(cat /dev/urandom | tr -dc 'A-Z0-9' | fold -w 22 | head -n 1)
CREATED=$(date -u "+%Y%m%dT%H%M%SZ")

$CURL -v  --user "$USER:$PASSW"  "$REMURL"  -T /dev/stdin <<-EOF
        PRODID: //My script

Regard the “-” between “<<” and “EOF”: that dash is required, if you use tabs to format your script to increase readability. It removes any tabs from the data stream.

Somehow, this kind of upload behaves completely different than the option “-T” plus reading from standard input as described in the manual. If someone knows why a HERE document works but the option “-T” does not work, I’d be happy to learn! :slight_smile: