Automatic calender entry

hello all,
I have my DAV calendar organized via owncloud (on Apache Server). To check if the connection between the server and a client was really updated I wanted to set a calendar entry automatically every day and delete yesterday’s entry. So far I can’t find a suitable approach for a script (Linux). Maybe someone here knows a similar project. Many thanks for your help

If you have searched, you should have come along here:

https://sabre.io/dav/building-a-caldav-client/

I dont want to learn a new way of building up a new Calendar. I just want to tell the existing one to build a new event and delete the similar one, as I wrote in my question. But thanks a lot.
Anyone else?

Cool down, please.
You want to add and delete calendar objects, right? Maybe I’ll look for an example, in case you are interested.

that would be nice, thank you

my system:
Raspi
Raspbian GNU/Linux
Server: Apache
owncloud vs 9.1.3.1

Quick & dirty™:

#!/bin/bash

SERVER=https://your.server.here
CALDAV=/remote.php/dav/calendars/
USER=your_user
CALENDAR=your_calendar
UUID=f7082864-9256-11ed-8353-2f1c8f98bf19
NOW=$(date +%Y%m%dT%H%M%S)

AddObject(){
	curl -n -X PUT -H "Content-Type: text/calendar; charset=utf-8" -d "
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//calendar//ping//EN
CALSCALE:GREGORIAN
BEGIN:VEVENT
DTSTAMP:$NOW
UID:${UUID}
SUMMARY:Calendar Ping
DTSTART:$NOW
DTEND:$NOW
CLASS:PUBLIC
END:VEVENT
END:VCALENDAR" ${SERVER}${CALDAV}${USER}/${CALENDAR}/${UUID}.ics
}

DeleteObject(){
	curl -n -X DELETE ${SERVER}${CALDAV}${USER}/${CALENDAR}/${UUID}.ics
}

The function AddObject() adds an entry with timestamp now. Tomorrow, you can call DeleteObject() followed by another AddObject(). And so on.

Kindly note that I’m using curl with credentials from ~/.netrc file. (curl -n)

HTH
abu

O wow,
thanks a lot. This weekend I should test it out.

1 Like

unfortunately the script does not work like this. I have divided it into two parts, once the addobject and once the delete. Have also created an calendar event which should be deleted (with the UUID). Since it always ran the same: no message + no effect I think, the communication with the server does not work. Two questions: is there no need for a password request? and: maybe there is a problem having the script beeing executed on the same device on which owncloud runs with the calendar?

#!/bin/sh

SERVER=###
CALDAV=###
USER=###
CALENDAR=###
UUID=###
NOW=$(date +%Y%m%dT%H%M%S)

AddObject(){
curl -n -X PUT -H “Content-Type: text/calendar; charset=utf-8” -d "
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN
CALSCALE:GREGORIAN
BEGIN:VEVENT
DTSTAMP:$NOW
UID:${UUID}
SUMMARY:You are up to date
DTSTART:$NOW
DTEND:$NOW
CLASS:PUBLIC
END:VEVENT
END:VCALENDAR" ${SERVER}${CALDAV}${USER}/${CALENDAR}/${UUID}.ics
}

My idea is, creating an object with a constant UUID, which never changed. This is no problem, since you delete the existing object, from yesterday, BEFORE you add the today object.

Of course there is! As I wrote above:

This is my favorite method. Otherwise, you’ll need to pass the credentials as
curl -u username:password ... .

Of course, the script is also working if invoked from the same machine, at least in my installation. :wink:
Consider checking the logs.

Hello Alfred,
have found out with the windows command line in the meantime what the problem is: my server uses a self-certified cert. I tried -k and --insecure (result=404) and also --cacert with path to the certificate. It does not work.

The logs (apache2 and owncloud) were inconspicuous and the -n was in fact new for me and I had replaced it with the -u user:password.

The 404 means “not found”. But in case you call DeleteObject for a non-existing item, you should also get something like this as a response.

<?xml version="1.0" encoding="utf-8"?>
<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
    <s:exception>Sabre\DAV\Exception\NotFound</s:exception>
    <s:message>Calendar object not found</s:message>
</d:error>

right. that looks familiar to me :wink:
I’ve read the 404 is the result of -k or --insecure.

Hmm, I strongly doubt that you get a 404 on certificate issues. But I’m not an expert…

My brain got hurt when reading that:

@brucebra Any success on the certificate issue?

Thank you for asking!
since i have experience with windows batch-files this was my way. After I spent a lot of time in the correct setting of the appropriate VEVENT helped in deleting the event this here:

Set CURL_CA_BUNDLE=“c:\curl\raspberrypi.pem”
curl -u user:PW -X DELETE %SERVER%%CALDAV%%USER%/%CALENDAR%/%UUID%.ics

but so far it is only possible to access my Raspi via its fixed IP here in the network, but not via external access, i.e. https://server.

It was important to set the correct time zone and to understand that DTSTART and DTEND can only contain values that can be entered by the client, i.e. something like

DTSTART;TZID=Europe/Berlin:20230129T004000
DTEND;TZID=Europe/Berlin:20230129T014000

instead of

DTSTART;TZID=Europe/Berlin:20230129T004122
DTEND;TZID=Europe/Berlin:20230129T014122

which leads without comment to the fact that it does not find the object (ICS).

Specifying the timezone is only required, if it differs from the server setting. It shouldn’t and doesn’t make any difference. I added the TZID to my script, no difference.

Please consider using iCalendar Validator for checking your objects.