mirror of
https://github.com/laurent22/joplin.git
synced 2026-06-18 20:16:34 +02:00
Doc: Fixes #9171: Fixed data API doc
This commit is contained in:
@@ -21,7 +21,9 @@ To prevent unauthorised applications from accessing the API, the calls must be a
|
||||
|
||||
This would be an example of valid cURL call using a token:
|
||||
|
||||
curl http://localhost:41184/notes?token=ABCD123ABCD123ABCD123ABCD123ABCD123
|
||||
```shell
|
||||
curl http://localhost:41184/notes?token=ABCD123ABCD123ABCD123ABCD123ABCD123
|
||||
```
|
||||
|
||||
In the documentation below, the token will not be specified every time however you will need to include it.
|
||||
|
||||
@@ -31,13 +33,17 @@ If needed you may also [request the token programmatically](https://github.com/l
|
||||
|
||||
All the calls, unless noted otherwise, receives and send **JSON data**. For example to create a new note:
|
||||
|
||||
curl --data '{ "title": "My note", "body": "Some note in **Markdown**"}' http://localhost:41184/notes
|
||||
```shell
|
||||
curl --data '{ "title": "My note", "body": "Some note in **Markdown**"}' http://localhost:41184/notes
|
||||
```
|
||||
|
||||
In the documentation below, the calls may include special parameters such as :id or :note_id. You would replace this with the item ID or note ID.
|
||||
|
||||
For example, for the endpoint `DELETE /tags/:id/notes/:note_id`, to remove the tag with ID "ABCD1234" from the note with ID "EFGH789", you would run for example:
|
||||
|
||||
curl -X DELETE http://localhost:41184/tags/ABCD1234/notes/EFGH789
|
||||
```shell
|
||||
curl -X DELETE http://localhost:41184/tags/ABCD1234/notes/EFGH789
|
||||
```
|
||||
|
||||
The four verbs supported by the API are the following ones:
|
||||
|
||||
@@ -50,11 +56,15 @@ The four verbs supported by the API are the following ones:
|
||||
|
||||
You can change the fields that will be returned by the API using the `fields=` query parameter, which takes a list of comma separated fields. For example, to get the longitude and latitude of a note, use this:
|
||||
|
||||
curl http://localhost:41184/notes/ABCD123?fields=longitude,latitude
|
||||
```shell
|
||||
curl http://localhost:41184/notes/ABCD123?fields=longitude,latitude
|
||||
```
|
||||
|
||||
To get the IDs only of all the tags:
|
||||
|
||||
curl http://localhost:41184/tags?fields=id
|
||||
```shell
|
||||
curl http://localhost:41184/tags?fields=id
|
||||
```
|
||||
|
||||
By default API results will contain the following fields: **id**, **parent_id**, **title**
|
||||
|
||||
@@ -71,15 +81,21 @@ You can specify how the results should be sorted using the `order_by` and `order
|
||||
|
||||
The following call for example will initiate a request to fetch all the notes, 10 at a time, and sorted by "updated_time" ascending:
|
||||
|
||||
curl http://localhost:41184/notes?order_by=updated_time&order_dir=ASC&limit=10
|
||||
```shell
|
||||
curl http://localhost:41184/notes?order_by=updated_time&order_dir=ASC&limit=10
|
||||
```
|
||||
|
||||
This will return a result like this
|
||||
|
||||
{ "items": [ /* 10 notes */ ], "has_more": true }
|
||||
```json
|
||||
{ "items": [ /* 10 notes */ ], "has_more": true }
|
||||
```
|
||||
|
||||
Then you will resume fetching the results using this query:
|
||||
|
||||
curl http://localhost:41184/notes?order_by=updated_time&order_dir=ASC&limit=10&page=2
|
||||
```shell
|
||||
curl http://localhost:41184/notes?order_by=updated_time&order_dir=ASC&limit=10&page=2
|
||||
```
|
||||
|
||||
Eventually you will get some results that do not contain an "has_more" paramater, at which point you will have retrieved all the results
|
||||
|
||||
@@ -213,21 +229,29 @@ Examples:
|
||||
|
||||
* Create a note from some Markdown text
|
||||
|
||||
curl --data '{ "title": "My note", "body": "Some note in **Markdown**"}' http://127.0.0.1:41184/notes
|
||||
```shell
|
||||
curl --data '{ "title": "My note", "body": "Some note in **Markdown**"}' http://127.0.0.1:41184/notes
|
||||
```
|
||||
|
||||
* Create a note from some HTML
|
||||
|
||||
curl --data '{ "title": "My note", "body_html": "Some note in <b>HTML</b>"}' http://127.0.0.1:41184/notes
|
||||
```shell
|
||||
curl --data '{ "title": "My note", "body_html": "Some note in <b>HTML</b>"}' http://127.0.0.1:41184/notes
|
||||
```
|
||||
|
||||
* Create a note and attach an image to it:
|
||||
|
||||
curl --data '{ "title": "Image test", "body": "Here is Joplin icon:", "image_data_url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAANZJREFUeNoAyAA3/wFwtO3K6gUB/vz2+Prw9fj/+/r+/wBZKAAExOgF4/MC9ff+MRH6Ui4E+/0Bqc/zutj6AgT+/Pz7+vv7++nu82c4DlMqCvLs8goA/gL8/fz09fb59vXa6vzZ6vjT5fbn6voD/fwC8vX4UiT9Zi//APHyAP8ACgUBAPv5APz7BPj2+DIaC2o3E+3o6ywaC5fT6gD6/QD9/QEVf9kD+/dcLQgJA/7v8vqfwOf18wA1IAIEVycAyt//v9XvAPv7APz8LhoIAPz9Ri4OAgwARgx4W/6fVeEAAAAASUVORK5CYII="}' http://127.0.0.1:41184/notes
|
||||
```shell
|
||||
curl --data '{ "title": "Image test", "body": "Here is Joplin icon:", "image_data_url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAANZJREFUeNoAyAA3/wFwtO3K6gUB/vz2+Prw9fj/+/r+/wBZKAAExOgF4/MC9ff+MRH6Ui4E+/0Bqc/zutj6AgT+/Pz7+vv7++nu82c4DlMqCvLs8goA/gL8/fz09fb59vXa6vzZ6vjT5fbn6voD/fwC8vX4UiT9Zi//APHyAP8ACgUBAPv5APz7BPj2+DIaC2o3E+3o6ywaC5fT6gD6/QD9/QEVf9kD+/dcLQgJA/7v8vqfwOf18wA1IAIEVycAyt//v9XvAPv7APz8LhoIAPz9Ri4OAgwARgx4W/6fVeEAAAAASUVORK5CYII="}' http://127.0.0.1:41184/notes
|
||||
```
|
||||
|
||||
#### Creating a note with a specific ID
|
||||
|
||||
When a new note is created, it is automatically assigned a new unique ID so **normally you do not need to set the ID**. However, if for some reason you want to set it, you can supply it as the `id` property. It needs to be a **32 characters long string** in hexadecimal. **Make sure it is unique**, for example by generating it using whatever GUID function is available in your programming language.
|
||||
|
||||
curl --data '{ "id": "00a87474082744c1a8515da6aa5792d2", "title": "My note with custom ID"}' http://127.0.0.1:41184/notes
|
||||
```shell
|
||||
curl --data '{ "id": "00a87474082744c1a8515da6aa5792d2", "title": "My note with custom ID"}' http://127.0.0.1:41184/notes
|
||||
```
|
||||
|
||||
### PUT /notes/:id
|
||||
|
||||
@@ -333,17 +357,23 @@ Creates a new resource
|
||||
|
||||
Creating a new resource is special because you also need to upload the file. Unlike other API calls, this one must have the "multipart/form-data" Content-Type. The file data must be passed to the "data" form field, and the other properties to the "props" form field. An example of a valid call with cURL would be:
|
||||
|
||||
curl -F 'data=@/path/to/file.jpg' -F 'props={"title":"my resource title"}' http://localhost:41184/resources
|
||||
```shell
|
||||
curl -F 'data=@/path/to/file.jpg' -F 'props={"title":"my resource title"}' http://localhost:41184/resources
|
||||
```
|
||||
|
||||
To **update** the resource content, you can make a PUT request with the same arguments:
|
||||
|
||||
curl -X PUT -F 'data=@/path/to/file.jpg' -F 'props={"title":"my modified title"}' http://localhost:41184/resources/8fe1417d7b184324bf6b0122b76c4696
|
||||
```shell
|
||||
curl -X PUT -F 'data=@/path/to/file.jpg' -F 'props={"title":"my modified title"}' http://localhost:41184/resources/8fe1417d7b184324bf6b0122b76c4696
|
||||
```
|
||||
|
||||
The "data" field is required, while the "props" one is not. If not specified, default values will be used.
|
||||
|
||||
Or if you only need to update the resource properties (title, etc.), without changing the content, you can make a regular PUT request:
|
||||
|
||||
curl -X PUT --data '{"title": "My new title"}' http://localhost:41184/resources/8fe1417d7b184324bf6b0122b76c4696
|
||||
```shell
|
||||
curl -X PUT --data '{"title": "My new title"}' http://localhost:41184/resources/8fe1417d7b184324bf6b0122b76c4696
|
||||
```
|
||||
|
||||
**From a plugin** the syntax to create a resource is also a bit special:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user