• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..13-Nov-2021-

README.mdH A D13-Nov-20215.9 KiB12283

v1.mdH A D13-Nov-202115.4 KiB296218

README.md

1# Rest API documentation of Nextcloud Notes
2
3The notes app comes with a REST-based API.
4It can be used in order to provide full access to notes from third-party apps.
5This documentation describes the API in detail.
6In this file, general information about the API is provided.
7The endpoint specification for a specific version can be found in separate files (see table below).
8
9
10## Major API versions
11
12| API version | Supported by app version | Documentation  |
13|:-----------:|:-------------------------|:--------|
14|  **1**      | since Notes 3.3 (May 2020)     | **[Documentation](v1.md)** |
15|  **0.2**    | since Notes 1.0 (2015)         | *(deprecated)* |
16
17
18## Versioning policy
19
20While the notes app evolves and receives new features, it may be required to adopt the API.
21As far as possible, we try to make these changes backward compatible.
22However, this is not always possible.
23Therefore, a versioning scheme is realized in order to not break clients using an older API version.
24We distinguish major and minor versions:
25
26- a major version comes with changes that are incompatible to the previous version and therefore would break old clients. Major versions come with a new base URL path.
27- a minor version has changes that are realized compatible to the previous version. Old clients can still use the current API endpoint, but they need adoption in order to use new features.
28
29### Compability between minor versions
30
31Minor versions of the same major version use the same API endpoint (path). Therefore, they must be compatible.
32
33In order to realize forward compatibility between minor versions, clients must follow some general rules regarding the API:
34
35- when processing the JSON response, unknown fields must be ignored (e.g. if API version 1.0 does not define the note's attribute "tags", a client must ignore such an unkown field in order to be compatible with a possible future version (e.g. 1.4) which defines such a field)
36- when processing the HTTP response code, a client must be able to handle newly introduced error codes (e.g. if API 1.0 does not explicitly define response code 405, the client must handle it at least like 400; same with a 5xx code).
37
38In order to realize backwards compatibility between minor versions, a client must follow the following rules:
39
40- when sending a request which uses a feature that wasn't available from beginning of the used major version, the client has to cope with the situation that the server ignores parts of the request
41- when processing the JSON response, the server may ommit fields that where not available from beginning of the used major version
42
43If a client requires a certain feature, it should check the list of supported API version from server (see *Capabilities*).
44
45
46### Capabilites
47
48From Notes app version 3.3, supported API versions can be queried using the [Nextcloud Capabilities API](https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-api-overview.html#capabilities-api).
49
50A request like
51
52	curl -u user:password -X GET -H "OCS-APIRequest: true" -H "Accept: application/json" https://yournextcloud.com/ocs/v2.php/cloud/capabilities
53
54will return the following result (in this example, irrelevant attributes are omitted and formatting was introduced):
55
56```json
57{
58  "ocs": {
59    "data": {
60      "capabilities": {
61        "notes": {
62          "api_version": [ "0.2", "1.0" ],
63          "version": "3.6.0"
64        }
65      }
66    }
67  }
68}
69```
70
71|  Attribute    | Type            | Description | since app version |
72|:--------------|:----------------|:------------|:------------------|
73| `api_version` | list of strings | list of supported API version; for each supported major API version, the highest supported minor API version is listed, e.g. `[ "0.2", "1.1" ]`  | Notes 3.3 |
74| `version`     | string          | app version, e.g. `"3.6.0"`  | Notes 3.6 |
75
76From Notes app version 3.3, the list of supported API versions is also provided in every response from the Notes API.
77For this, the HTTP header `X-Notes-API-Versions` is used.
78It contains a coma-separated list of versions, e.g., `X-Notes-API-Versions: 0.2, 1.0`.
79
80### Processing API version information
81In order to be compatible to older Notes version, you may want to implement multiple API versions in your client application.
82In this case, you should periodically request OCS capabilities from the server or parse the `X-Notes-API-Versions` HTTP header.
83Your application must then walk through the list of supported API versions and for each version do:
841. parse the version string (e.g. `1.2`) and gather the major version (here: `1`) as well as the minor version (here: `2`)
852. check if your client app supports the major version and then check if the minor version is greater or equal than your minimum required minor version for that major version
86
87Then use the highest API version to which this requirement applies.
88
89## Authentication
90
91Because REST is stateless you have to send user and password each time you access the API.
92Therefore running Nextcloud **with SSL is highly recommended** otherwise **everyone in your network can log your credentials**.
93
94You can test your request using `curl`:
95
96    curl -u user:password -H "Accept: application/json" https://yournextcloud.com/index.php/apps/notes/api/v1/notes
97
98If you have enabled two-factor authentication you will have to create an app specific password for accessing the API. Please see [Nextcloud documentation](https://docs.nextcloud.com/server/latest/user_manual/session_management.html) for further details.
99
100## Input parameters
101
102In general the input parameters can be in the URL or request body. The app framework doesn't differentiate between them.
103
104Therefore, JSON in the request body like:
105```js
106{
107  "id": 3
108}
109```
110will be treated the same as
111
112    /?id=3
113
114It is recommended though that you use the following convention:
115
116* **GET**: parameters in the URL
117* **POST**: parameters as JSON in the request body
118* **PUT**: parameters as JSON in the request body
119* **DELETE**: parameters as JSON in the request body
120
121The output is JSON.
122