<p><ahref="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=E8JMYD2LQ8MMA&lc=GB&item_name=Joplin+Development&currency_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted"><imgsrc="https://raw.githubusercontent.com/laurent22/joplin/dev/Assets/WebsiteAssets/images/badges/Donate-PayPal-green.svg"alt="Donate using PayPal"></a><ahref="https://github.com/sponsors/laurent22/"><imgsrc="https://raw.githubusercontent.com/laurent22/joplin/dev/Assets/WebsiteAssets/images/badges/GitHub-Badge.svg"alt="Sponsor on GitHub"></a><ahref="https://www.patreon.com/joplin"><imgsrc="https://raw.githubusercontent.com/laurent22/joplin/dev/Assets/WebsiteAssets/images/badges/Patreon-Badge.svg"alt="Become a patron"></a><ahref="https://joplinapp.org/donate/#donations"><imgsrc="https://raw.githubusercontent.com/laurent22/joplin/dev/Assets/WebsiteAssets/images/badges/Donate-IBAN.svg"alt="Donate using IBAN"></a></p>
</div>
<h1>Joplin Data API<aname="joplin-data-api"href="#joplin-data-api"class="heading-anchor">🔗</a></h1>
<p>This API is available when the clipper server is running. It provides access to the notes, notebooks, tags and other Joplin object via a REST API. Plugins can also access this API even when the clipper server is not running.</p>
<p>In order to use it, you'll first need to find on which port the service is running. To do so, open the Web Clipper Options in Joplin and if the service is running it should tell you on which port. Normally it runs on port <strong>41184</strong>. If you want to find it programmatically, you may follow this kind of algorithm:</p>
<pre><codeclass="language-javascript">let port = null;
for (let portToTest = 41184; portToTest <= 41194; portToTest++) {
const result = pingPort(portToTest); // Call GET /ping
<p>To prevent unauthorised applications from accessing the API, the calls must be authentified. To do so, you must provide a token as a query parameter for each API call. You can get this token from the Joplin desktop application, on the Web Clipper Options screen.</p>
<p>This would be an example of valid cURL call using a token:</p>
<p>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.</p>
<p>For example, for the endpoint <code>DELETE /tags/:id/notes/:note_id</code>, to remove the tag with ID "ABCD1234" from the note with ID "EFGH789", you would run for example:</p>
<p>The four verbs supported by the API are the following ones:</p>
<ul>
<li><strong>GET</strong>: To retrieve items (notes, notebooks, etc.).</li>
<li><strong>POST</strong>: To create new items. In general most item properties are optional. If you omit any, a default value will be used.</li>
<li><strong>PUT</strong>: To update an item. Note in a REST API, traditionally PUT is used to completely replace an item, however in this API it will only replace the properties that are provided. For example if you PUT {"title": "my new title"}, only the "title" property will be changed. The other properties will be left untouched (they won't be cleared nor changed).</li>
<li><strong>DELETE</strong>: To delete items.</li>
<p>You can change the fields that will be returned by the API using the <code>fields=</code> query parameter, which takes a list of comma separated fields. For example, to get the longitude and latitude of a note, use this:</p>
<p>All API calls that return multiple results will be paginated and will return the following structure:</p>
<tableclass="table">
<thead>
<tr>
<th>Key</th>
<th>Always present?</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>items</code></td>
<td>Yes</td>
<td>The array of items you have requested.</td>
</tr>
<tr>
<td><code>has_more</code></td>
<td>Yes</td>
<td>If <code>true</code>, there are more items after this page. If <code>false</code>, it means you have reached the end of the data set.</td>
</tr>
</tbody>
</table>
<p>You can specify how the results should be sorted using the <code>order_by</code> and <code>order_dir</code> query parameters, and which page to retrieve using the <code>page</code> parameter (starts at and defaults to 1). You can specify the number of items to be returned using the <code>limit</code> parameter (the maximum being 100 items).</p>
<p>The following call for example will initiate a request to fetch all the notes, 10 at a time, and sorted by "updated_time" ascending:</p>
<p>Eventually you will get some results that do not contain an "has_more" paramater, at which point you will have retrieved all the results</p>
<p>As an example the pseudo-code below could be used to fetch all the notes:</p>
<p>In case of an error, an HTTP status code >= 400 will be returned along with a JSON object that provides more info about the error. The JSON object is in the format <code>{ "error": "description of error" }</code>.</p>
<h1>About the property types<aname="about-the-property-types"href="#about-the-property-types"class="heading-anchor">🔗</a></h1>
<ul>
<li>Text is UTF-8.</li>
<li>All date/time are Unix timestamps in milliseconds.</li>
<li>Booleans are integer values 0 or 1.</li>
</ul>
<h1>Testing if the service is available<aname="testing-if-the-service-is-available"href="#testing-if-the-service-is-available"class="heading-anchor">🔗</a></h1>
<p>Call <strong>GET /ping</strong> to check if the service is available. It should return "JoplinClipperServer" if it works.</p>
<p>Call <strong>GET /search?query=YOUR_QUERY</strong> to search for notes. This end-point supports the <code>field</code> parameter which is recommended to use so that you only get the data that you need. The query syntax is as described in the main documentation: <ahref="https://joplinapp.org/help/#searching">https://joplinapp.org/help/#searching</a></p>
<p>To retrieve non-notes items, such as notebooks or tags, add a <code>type</code> parameter and set it to the required <ahref="#item-type-id">item type name</a>. In that case, full text search will not be used - instead it will be a simple case-insensitive search. You can also use <code>*</code> as a wildcard. This is convenient for example to retrieve notebooks or tags by title.</p>
<p>For example, to retrieve the notebook named <code>recipes</code>: <strong>GET /search?query=recipes&type=folder</strong></p>
<p>To retrieve all the tags that start with <code>project-</code>: <strong>GET /search?query=project-*&type=tag</strong></p>
<h1>Item type IDs<aname="item-type-ids"href="#item-type-ids"class="heading-anchor">🔗</a></h1>
<p>Item type IDs might be refered to in certain object you will retrieve from the API. This is the correspondance between name and ID:</p>
<td>ID of the notebook that contains this note. Change this ID to move the note to a different notebook.</td>
</tr>
<tr>
<td>title</td>
<td>text</td>
<td>The note title.</td>
</tr>
<tr>
<td>body</td>
<td>text</td>
<td>The note body, in Markdown. May also contain HTML.</td>
</tr>
<tr>
<td>created_time</td>
<td>int</td>
<td>When the note was created.</td>
</tr>
<tr>
<td>updated_time</td>
<td>int</td>
<td>When the note was last updated.</td>
</tr>
<tr>
<td>is_conflict</td>
<td>int</td>
<td>Tells whether the note is a conflict or not.</td>
</tr>
<tr>
<td>latitude</td>
<td>numeric</td>
<td></td>
</tr>
<tr>
<td>longitude</td>
<td>numeric</td>
<td></td>
</tr>
<tr>
<td>altitude</td>
<td>numeric</td>
<td></td>
</tr>
<tr>
<td>author</td>
<td>text</td>
<td></td>
</tr>
<tr>
<td>source_url</td>
<td>text</td>
<td>The full URL where the note comes from.</td>
</tr>
<tr>
<td>is_todo</td>
<td>int</td>
<td>Tells whether this note is a todo or not.</td>
</tr>
<tr>
<td>todo_due</td>
<td>int</td>
<td>When the todo is due. An alarm will be triggered on that date.</td>
</tr>
<tr>
<td>todo_completed</td>
<td>int</td>
<td>Tells whether todo is completed or not. This is a timestamp in milliseconds.</td>
</tr>
<tr>
<td>source</td>
<td>text</td>
<td></td>
</tr>
<tr>
<td>source_application</td>
<td>text</td>
<td></td>
</tr>
<tr>
<td>application_data</td>
<td>text</td>
<td></td>
</tr>
<tr>
<td>order</td>
<td>numeric</td>
<td></td>
</tr>
<tr>
<td>user_created_time</td>
<td>int</td>
<td>When the note was created. It may differ from created_time as it can be manually set by the user.</td>
</tr>
<tr>
<td>user_updated_time</td>
<td>int</td>
<td>When the note was last updated. It may differ from updated_time as it can be manually set by the user.</td>
</tr>
<tr>
<td>encryption_cipher_text</td>
<td>text</td>
<td></td>
</tr>
<tr>
<td>encryption_applied</td>
<td>int</td>
<td></td>
</tr>
<tr>
<td>markup_language</td>
<td>int</td>
<td></td>
</tr>
<tr>
<td>is_shared</td>
<td>int</td>
<td></td>
</tr>
<tr>
<td>share_id</td>
<td>text</td>
<td></td>
</tr>
<tr>
<td>conflict_original_id</td>
<td>text</td>
<td></td>
</tr>
<tr>
<td>master_key_id</td>
<td>text</td>
<td></td>
</tr>
<tr>
<td>body_html</td>
<td>text</td>
<td>Note body, in HTML format</td>
</tr>
<tr>
<td>base_url</td>
<td>text</td>
<td>If <code>body_html</code> is provided and contains relative URLs, provide the <code>base_url</code> parameter too so that all the URLs can be converted to absolute ones. The base URL is basically where the HTML was fetched from, minus the query (everything after the '?'). For example if the original page was <code>https://stackoverflow.com/search?q=%5Bjava%5D+test</code>, the base URL is <code>https://stackoverflow.com/search</code>.</td>
</tr>
<tr>
<td>image_data_url</td>
<td>text</td>
<td>An image to attach to the note, in <ahref="https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs">Data URL</a> format.</td>
</tr>
<tr>
<td>crop_rect</td>
<td>text</td>
<td>If an image is provided, you can also specify an optional rectangle that will be used to crop the image. In format <code>{ x: x, y: y, width: width, height: height }</code></td>
<h3>Creating a note with a specific ID<aname="creating-a-note-with-a-specific-id"href="#creating-a-note-with-a-specific-id"class="heading-anchor">🔗</a></h3>
<p>When a new note is created, it is automatically assigned a new unique ID so <strong>normally you do not need to set the ID</strong>. However, if for some reason you want to set it, you can supply it as the <code>id</code> property. It needs to be a <strong>32 characters long string</strong> in hexadecimal. <strong>Make sure it is unique</strong>, for example by generating it using whatever GUID function is available in your programming language.</p>
<p>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:</p>
<p>Post a note to this endpoint to add the tag to the note. The note data must at least contain an ID property (all other properties will be ignored).</p>
<p>Returns a paginated list of recent events. A <code>cursor</code> property should be provided, which tells from what point in time the events should be returned. The API will return a <code>cursor</code> property, to tell from where to resume retrieving events, as well as an <code>has_more</code> (tells if more changes can be retrieved) and <code>items</code> property, which will contain the list of events. Events are kept for up to 90 days.</p>
<p>If no <code>cursor</code> property is provided, the API will respond with the latest change ID. That can be used to retrieve future events later on.</p>
<p>The results are paginated so will need to may multiple calls to retrieve all the events. Use the <code>has_more</code> property to know if more can be retrieved.</p>