OCS APIs overview

This document provides a quick overview of the OCS API endpoints supported in Nextcloud.

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

Testing requests with curl

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

For example: you can perform a GET request to get information about a user:

  1. curl -u username:password -X GET 'https://cloud.example.com/ocs/v1.php/...' -H "OCS-APIRequest: true"

User metadata

Since: 11.0.2, 12.0.0

This request returns the available metadata of a user. Admin users can see the information of all users, while a default user only can access it’s own metadata.

  1. GET /ocs/v1.php/cloud/users/USERID
  1. <?xml version="1.0"?>
  2. <ocs>
  3. <meta>
  4. <status>ok</status>
  5. <statuscode>100</statuscode>
  6. <message>OK</message>
  7. <totalitems></totalitems>
  8. <itemsperpage></itemsperpage>
  9. </meta>
  10. <data>
  11. <enabled>1</enabled>
  12. <storageLocation>/path/to/storage/location/userid</storageLocation>
  13. <id>userid</id>
  14. <lastLogin>1578283711000</lastLogin>
  15. <backend>Database</database>
  16. <subadmin/>
  17. <quota>
  18. <free>20632824998</free>
  19. <used>842011482</used>
  20. <total>21474836480</total>
  21. <relative>3.92</relative>
  22. <quota>21474836480</quota>
  23. </quota>
  24. <email>user@foo.de</email>
  25. <displayname>John Doe</displayname>
  26. <phone></phone>
  27. <address></address>
  28. <website>https://example.com</website>
  29. <twitter></twitter>
  30. <groups>
  31. <element>1st group</element>
  32. <element>2nd group</element>
  33. <element>3rd group</element>
  34. <element>... group</element>
  35. </groups>
  36. <language>de</language>
  37. <locale>de_DE</locale>
  38. <backendCapabilities>
  39. <setDisplayName>1</setDisplayName>
  40. <setPassword>1</setPassword>
  41. </backendCapabilities>
  42. </data>
  43. </ocs>

User metadata - List user IDs

This request returns a list containing all user IDs. Only admin users can query the list.

  1. GET /ocs/v1.php/cloud/users
  1. <?xml version="1.0"?>
  2. <ocs>
  3. <meta>
  4. <status>ok</status>
  5. <statuscode>100</statuscode>
  6. <message>OK</message>
  7. <totalitems></totalitems>
  8. <itemsperpage></itemsperpage>
  9. </meta>
  10. <data>
  11. <users>
  12. <element>1st_user</element>
  13. <element>2nd_user</element>
  14. <element>3rd_user</element>
  15. <element>..._user</element>
  16. </users>
  17. </data>
  18. </ocs>

Capabilities API

Clients can obtain capabilities provided by the Nextcloud server and its apps via the capabilities OCS API.

  1. GET /ocs/v1.php/cloud/capabilities
  1. <?xml version="1.0"?>
  2. <ocs>
  3. <meta>
  4. <status>ok</status>
  5. <statuscode>100</statuscode>
  6. <message>OK</message>
  7. <totalitems></totalitems>
  8. <itemsperpage></itemsperpage>
  9. </meta>
  10. <data>
  11. <version>
  12. <major>17</major>
  13. <minor>0</minor>
  14. <micro>2</micro>
  15. <string>17.0.2</string>
  16. <edition></edition>
  17. <extendedSupport></extendedSupport>
  18. </version>
  19. <capabilities>
  20. <core>
  21. <pollinterval>60</pollinterval>
  22. <webdav-root>remote.php/webdav</webdav-root>
  23. </core>
  24. </capabilities>
  25. </data>
  26. </ocs>

Theming capabilities

Values of the theming app are exposed through the capabilities API, allowing client developers to adjust the look of clients to the theming of different Nextcloud instances.

  1. <theming>
  2. <name>Nextcloud</name>
  3. <url>https://nextcloud.com</url>
  4. <slogan>A safe home for all your data</slogan>
  5. <color>#0082c9</color>
  6. <color-text>#ffffff</color-text>
  7. <color-element>#0082c9</color-element>
  8. <color-element-bright>#aaaaaa</color-element-bright>
  9. <color-element-dark>#555555</color-element-dark>
  10. <logo>http://cloud.example.com/index.php/apps/theming/logo?v=1</logo>
  11. <background>http://cloud.example.com/index.php/apps/theming/logo?v=1</background>
  12. <background-plain></background-plain>
  13. <background-default></background-default>
  14. </theming>

For elements like radio buttons, input borders and more, instead of the primary color value, the color-element-bright should be used on bright background and color-element-dark on dark background. This when the primary color is e.g. set to #000000 the color-elemenet-dark will be set to #555555 so items are still visible. In the Nextcloud web UI only the top header uses color, everything else uses color-element-*. Text and icons on these elements should use color-text.

The background value can either be an URL to the background image or a hex color value.

Direct Download

It might be required to give a 3rd party access to a file however you do not want to hand over credentials to the 3rd party. An example of this is playing files in an external media player on mobile devices.

To solve this issue there is a way to request a unique public link to a single file. This link will be valid for 8 hours afterwards it will be removed.

To obtain a direct link:

  1. POST /ocs/v2.php/apps/dav/api/v1/direct

With the fileId in the body (so fileId=42 for example). This will then return you the link to use to obtain the file.

Notifications

There is also the Notifications API As well as documentation on how to Register a device for push notifications

Auto-complete and user search

It is possible to search for users using the auto-complete API, used to auto-complete usernames in comments, chat or to find guest accounts. The code can be found here

An example curl command would be:

  1. curl -i -u master -X GET -H "OCS-APIRequest: true" 'https://my.nextcloud/ocs/v2.php/core/autocomplete/get?search=JOANNE%40EMAIL.ISP&itemType=%20&itemId=%20&shareTypes[]=8&limit=2'

That would look for JOANNE@EMAIL.ISP as guest user. Maximum 2 results to be returned for a regular user, the shareTypes array would carry only “0”. itemType and itemId are left (set to a white space), essentially they are to give context about the use case, so sorters can do their work (like who commented last). It can be an option for filtering on a later stage but you can also leave them out as per the below example.

  1. curl -i -u master -X GET -H "OCS-APIRequest: true" 'https://my.nextcloud/ocs/v2.php/core/autocomplete/get?search=JOANNE%40EMAIL.ISP&shareTypes[]=8&limit=2'

The shareType would default to regular users if you left it out), the limit defaults to 10.