CalDAV API and Trashbin

Hey…
i was using a simple code to push ics files to a nextcloud calendar.
This worked good… i also was able to delete and reupload again… or just upload again and overwrite…

but since any update (i don’t know which), there seems to be a trashbin for deleted calendar events. and now, when i delete an event and after that i want to reupload it, i get a UID error…

Deleted calendar object with uid already exists in this calendar collection.

This - for sure - makes sense… but how to access those deleted calendar objects to undelete or delete from trashbin?

The “standard”-trashbin doesn’t seem to host those files… i can’t find them via this api:
https://docs.nextcloud.com/server/latest/developer_manual/client_apis/WebDAV/trashbin.html

Since i wasn’t able to find an API for accessing CalDAV-Trashbin, i tried to find all calendars… and i found a trashbin-Calendar via:

curl -s -X PROPFIND https://USER:PASS@cloud/remote.php/dav/calendars/USER/

After digging deeper, i found:

/remote.php/dav/calendars/USER/trashbin/restore
/remote.php/dav/calendars/USER/trashbin/objects

Digging even deeper via
got me this to have all events in trashbin parsed:

curl -s -X REPORT https://USER:PASS@cloud/remote.php/dav/calendars/USER/trashbin/objects --upload-file - -H "Depth: 1" <<end
<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
    <d:prop>
        <d:getetag />
        <c:calendar-data />
    </d:prop>
    <c:filter>
        <c:comp-filter name="VCALENDAR" />
    </c:filter>
</c:calendar-query>
end

but thats not realy what i wanted… i don’t want to display all the ICS data… i want to get the correct file…

so i tried to filter like this…

curl -s -X REPORT https://USER:PASS@cloud/remote.php/dav/calendars/USER/trashbin/objects --upload-file - -H "Depth: 1" <<end
<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
    <d:prop>
        <d:getetag />
        <c:calendar-data />
    </d:prop>
    <c:filter>
        <c:comp-filter name="VCALENDAR">
            <c:comp-filter name="VEVENT">
                <c:prop-filter name="UID">
                    <c:text-match collation="i;octet">my-uid</c:text-match>
                </c:prop-filter>
            </c:comp-filter>
        </c:comp-filter>
   </c:filter>
</c:calendar-query>
end

but this filter is not working…

well… downloading the complete data… and parsing + filtering localy is slow as hell…

whats a good solution to undelete or delete from trashbin?
And is there any kind of API Documentation?

I don’t know if there is an api for the caldav trashbin. Do you need the caldav trashbin? If not, you could just disable it with setting the according config value to 0: https://docs.nextcloud.com/server/22/admin_manual/groupware/calendar.html#trash-bin

This will disable the caldav trashbin completely. Remaining items in the trashbin will be removed with the next run of the caldav-trashbinRetention job (this is every 6 hours the case).

Thanks, this workaround is maybe the last chance… but i am realy interested in knowing more about caldav trashbin usage.

Maybe it helps, if you examinize the requests of the webinterface when you delete/undelete an event from the caldav-trashbin.

1 Like

the API isn’t documented because we didn’t expect anyone to use it apart form our own front-end.

the situation that you can not overwrite previously deleted items is a bug: https://github.com/nextcloud/server/issues/30096. we plan to fix this.

ah ok… thx a lot…
as this is a bug, that needs to be fixed… would you recommend to wait a few days/weeks… or just use a workaround?
In other words: could you say if someone is working on this bug at the moment and is it to be soon fixed or probably later?

it’s scheduled but I can’t give you an eta. currently we are waiting for the merge of https://github.com/nextcloud/server/pull/30120. if you would like to help you could check out the code and give it a good test or review.

I would love to help… but i am not a coder… i am a code-snippet-hunter on the internet =)

1 Like