Basic APIs

This document provides a quick overview of the WebDAV operations supported in Nextcloud, to keep things readable it won’t go into many details for each operation, further information for each operation can be found in the corresponding rfc where applicable

WebDAV basics

The base url for all WebDAV operations for a Nextcloud instance is /remote.php/dav.

All requests need to provide authentication information, either as a Basic Auth header or by passing a set of valid session cookies.

Testing requests with curl

All WebDAV requests can be easily tested out using curl by specifying the request method (GET, PROPFIND, PUT, etc) and setting a request body where needed.

For example: you can perform a PROPFIND request to find files in a folder using

  1. curl -u username:password 'https://cloud.example.com/remote.php/dav/files/username/folder' -X PROPFIND --data '<?xml version="1.0" encoding="UTF-8"?>
  2. <d:propfind xmlns:d="DAV:">
  3. <d:prop xmlns:oc="http://owncloud.org/ns">
  4. <d:getlastmodified/>
  5. <d:getcontentlength/>
  6. <d:getcontenttype/>
  7. <oc:permissions/>
  8. <d:resourcetype/>
  9. <d:getetag/>
  10. </d:prop>
  11. </d:propfind>'

Listing folders (rfc4918)

The contents of a folder can be listed by sending a PROPFIND request to the folder.

  1. PROPFIND remote.php/dav/files/user/path/to/folder

Requesting properties

By default, a PROPFIND request will only return a small number of properties for each file: last modified date, file size, whether it’s a folder, etag and mime type.

You can request additional properties by sending a request body with the PROPFIND request that lists all requested properties.

  1. <?xml version="1.0"?>
  2. <d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns">
  3. <d:prop>
  4. <d:getlastmodified />
  5. <d:getetag />
  6. <d:getcontenttype />
  7. <d:resourcetype />
  8. <oc:fileid />
  9. <oc:permissions />
  10. <oc:size />
  11. <d:getcontentlength />
  12. <nc:has-preview />
  13. <oc:favorite />
  14. <oc:comments-unread />
  15. <oc:owner-display-name />
  16. <oc:share-types />
  17. </d:prop>
  18. </d:propfind>

The following properties are supported:

  • {DAV:}getlastmodified
  • {DAV:}getetag
  • {DAV:}getcontenttype
  • {DAV:}resourcetype
  • {DAV:}getcontentlength
  • {http://owncloud.org/ns}id The fileid namespaced by the instance id, globally unique
  • {http://owncloud.org/ns}fileid The unique id for the file within the instance
  • {http://owncloud.org/ns}favorite
  • {http://owncloud.org/ns}comments-href
  • {http://owncloud.org/ns}comments-count
  • {http://owncloud.org/ns}comments-unread
  • {http://owncloud.org/ns}owner-id The user id of the owner of a shared file
  • {http://owncloud.org/ns}owner-display-name The display name of the owner of a shared file
  • {http://owncloud.org/ns}share-types
  • {http://owncloud.org/ns}checksums
  • {http://nextcloud.org/ns}has-preview
  • {http://owncloud.org/ns}size Unlike getcontentlength, this property also works for folders reporting the size of everything in the folder.
  • {http://nextcloud.org/ns}rich-workspace this property is provided by the text app

Getting properties for just the folder

You can request properties of a folder without also getting the folder contents by adding a Depth: 0 header to the request.

Downloading files

A file can be downloaded by sending a GET request to the WebDAV url of the file.

  1. GET remote.php/dav/files/user/path/to/file

Uploading files

A file can be uploading by sending a PUT request to the file and sending the raw file contents as the request body.

  1. PUT remote.php/dav/files/user/path/to/file

Any existing file will be overwritten by the request.

Creating folders (rfc4918)

A folder can be created by sending a MKCOL request to the folder.

  1. MKCOL remote.php/dav/files/user/path/to/new/folder

Deleting files and folders (rfc4918)

A file or folder can be deleted by sending a DELETE request to the file or folder.

  1. DELETE remote.php/dav/files/user/path/to/file

When deleting a folder, it’s contents will be deleted recursively.

Moving files and folders (rfc4918)

A file or folder can be moved by sending a MOVE request to the file or folder and specifying the destination in the Destination header as full url.

  1. MOVE remote.php/dav/files/user/path/to/file
  2. Destination: https://cloud.example/remote.php/dav/files/user/new/location

The overwrite behavior of the move can be controlled by setting the Overwrite head to T or F to enable or disable overwriting respectively.

Copying files and folders (rfc4918)

A file or folder can be copied by sending a COPY request to the file or folder and specifying the destination in the Destination header as full url.

  1. COPY remote.php/dav/files/user/path/to/file
  2. Destination: https://cloud.example/remote.php/dav/files/user/new/location

The overwrite behavior of the copy can be controlled by setting the Overwrite head to T or F to enable or disable overwriting respectively.

Settings favorites

A file or folder can be marked as favorite by sending a PROPPATCH request to the file or folder and setting the oc-favorite property

  1. PROPPATCH remote.php/dav/files/user/path/to/file
  2. <?xml version="1.0"?>
  3. <d:propertyupdate xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns">
  4. <d:set>
  5. <d:prop>
  6. <oc:favorite>1</oc:favorite>
  7. </d:prop>
  8. </d:set>
  9. </d:propertyupdate>

Setting the oc:favorite property to 1 marks a file as favorite, setting it to 0 un-marks it as favorite.

Listing favorites

Favorites for a user can be retrieved by sending a REPORT request and specifying oc:favorite as a filter

  1. REPORT remote.php/dav/files/user/path/to/folder
  2. <?xml version="1.0"?>
  3. <oc:filter-files xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns">
  4. <oc:filter-rules>
  5. <oc:favorite>1</oc:favorite>
  6. </oc:filter-rules>
  7. </oc:filter-files>

File properties can be requested by adding a <d:prop/> element to the request listing the requested properties in the same way as it would be done for a PROPFIND request.

When listing favorites, the request will find all favorites in the folder recursively, all favorites for a user can be found by sending the request to remote.php/dav/files/user