Joplin API - Python

Here is the Python version for the support of Joplin API available from https://github.com/foxmask/joplin-api

example of the way to create notes, ping the server, get notes and tags

>>> from joplin_api import JoplinApi
>>> joplin = JoplinApi(token='the token provided by Joplin in the WebClipper menu:P'))
>>> joplin.ping()  # to check if the service is up
>>> joplin.get_folders() # to get all the folders
>>> folder_title = 'Default'
>>> folder = joplin.create_folder(folder_title) # to create a folder
>>> # to create a new note
>>> note_title = 'My title'
>>> note_body = '# My Title ## My Subtitle my body'
>>> joplin.create_note(note_title, note_body, folder['id'])
>>> joplin.get_notes() # to get all the notes
>>> joplin.get_tags() # to get all the tags
6 Likes

It seems that I failed by installing the api:

At first, I installed Git from here: https://git-scm.com/download/win

In the git bash I called this

git clone  https://github.com/foxmask/joplin-api
cd joplin-api 
python setup.py install

Everything seemed to run fine. But when I call the first line of your script,

from joplin_api import JoplinApi

this happens:

Traceback (most recent call last):
  File "H:\Dropbox\400 - Scriptprogrammierung\Python3\Joplin\JoplinAPI_Uwe.py", line 1, in <module>
    from joplin_api import JoplinApi
ModuleNotFoundError: No module named 'joplin_api

What are the steps to install the Joplin API in Windows 10 64bit so that I can run a python script?

It’s ok on Windows that way. I fixed that behaviour but didn’t push it

should be better, let me know if you meet other issue

Thank you, this issue is solved. But the next one is here:

Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
=================== RESTART: H:\Dropbox\400 - Scriptprogrammierung\Python3\Joplin\JoplinAPI_Uwe.py ===================
Traceback (most recent call last):
  File "H:\Dropbox\400 - Scriptprogrammierung\Python3\Joplin\JoplinAPI_Uwe.py", line 5, in <module>
    joplin.ping()  # to check if the service is up
  File "C:\Users\Uwe Wennmann\AppData\Local\Programs\Python\Python37\lib\site-packages\joplin_api-1.2.2-py3.7.egg\joplin_api\core.py", line 451, in ping
    res = self.query('get', 'ping', **{})
  File "C:\Users\Uwe Wennmann\AppData\Local\Programs\Python\Python37\lib\site-packages\joplin_api-1.2.2-py3.7.egg\joplin_api\core.py", line 66, in query
    raise ValueError(f'request expected: notes, folders, tags, '
ValueError: request expected: notes, folders, tags, resources, version or ping but not ping
>>>

ok I fixed that :slight_smile:
thanks for reporting.
do a git pull and let me know

The output of git pull looks well…

$ git pull
remote: Enumerating objects: 14, done.
remote: Counting objects: 100% (14/14), done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 14 (delta 7), reused 14 (delta 7), pack-reused 0
Unpacking objects: 100% (14/14), done.
From https://github.com/foxmask/joplin-api
   d879979..b29dcf5  master     -> origin/master
Updating d879979..b29dcf5
Fast-forward
 README.md          |  1 -
 joplin_api/core.py | 20 +++-----------------
 test.py            |  1 -
 3 files changed, 3 insertions(+), 19 deletions(-)

… but not the output of python, when I run the script:

Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
=================== RESTART: H:\Dropbox\400 - Scriptprogrammierung\Python3\Joplin\JoplinAPI_Uwe.py ===================
Traceback (most recent call last):
  File "H:\Dropbox\400 - Scriptprogrammierung\Python3\Joplin\JoplinAPI_Uwe.py", line 5, in <module>
    joplin.ping()  # to check if the service is up
  File "C:\Users\Uwe Wennmann\AppData\Local\Programs\Python\Python37\lib\site-packages\joplin_api-1.2.2-py3.7.egg\joplin_api\core.py", line 451, in ping
    res = self.query('get', 'ping', **{})
  File "C:\Users\Uwe Wennmann\AppData\Local\Programs\Python\Python37\lib\site-packages\joplin_api-1.2.2-py3.7.egg\joplin_api\core.py", line 66, in query
    raise ValueError(f'request expected: notes, folders, tags, '
ValueError: request expected: notes, folders, tags, resources, version or ping but not ping

After git pull you need to redo

pip install -e .
1 Like

I did pip install -e . and got this:

    Obtaining file:///C:/Users/Uwe%20Wennmann/joplin-api
    Requirement already satisfied: requests==2.20.0 in c:\users\uwe wennmann\appdata\local\programs\python\python37\lib\site-packages (from joplin-api==1.2.2) (2.20.0)
    Requirement already satisfied: urllib3<1.25,>=1.21.1 in c:\users\uwe wennmann\appdata\local\programs\python\python37\lib\site-packages (from requests==2.20.0->joplin-api==1.2.2) (1.24)
    Requirement already satisfied: idna<2.8,>=2.5 in c:\users\uwe wennmann\appdata\local\programs\python\python37\lib\site-packages (from requests==2.20.0->joplin-api==1.2.2) (2.7)
    Requirement already satisfied: certifi>=2017.4.17 in c:\users\uwe wennmann\appdata\local\programs\python\python37\lib\site-packages (from requests==2.20.0->joplin-api==1.2.2) (2018.10.15)
    Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\users\uwe wennmann\appdata\local\programs\python\python37\lib\site-packages (from requests==2.20.0->joplin-api==1.2.2) (3.0.4)
    Installing collected packages: joplin-api
      Found existing installation: joplin-api 1.2.2
        Uninstalling joplin-api-1.2.2:
          Successfully uninstalled joplin-api-1.2.2
      Running setup.py develop for joplin-api
    Successfully installed joplin-api

Then I started the script again, and got this:

Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
=================== RESTART: H:\Dropbox\400 - Scriptprogrammierung\Python3\Joplin\JoplinAPI_Uwe.py ===================
method get path http://127.0.0.1:41184/ping/ params {'token': 'MYTOKEN'} payload {} headers {'Content-Type': 'application/json'}
Response of WebClipper <Response [200]>
method get path http://127.0.0.1:41184/folders/ params {'token': 'MYTOKEN'} payload {} headers {'Content-Type': 'application/json'}
Response of WebClipper <Response [200]>
method post path http://127.0.0.1:41184/folders/ params {'token': 'MYTOKEN'} payload {'title': 'Default', 'parent_id': 0} headers {'Content-Type': 'application/json'}
Response of WebClipper <Response [200]>
Traceback (most recent call last):
  File "H:\Dropbox\400 - Scriptprogrammierung\Python3\Joplin\JoplinAPI_Uwe.py", line 13, in <module>
    joplin.create_note(note_title, note_body, folder['id'])
TypeError: 'Response' object is not subscriptable
>>> 

(MYTOKEN was my Token from Joplin)

If you could paste your code to check what’s wrong, could be helpful.

The code was stolen from GitHub - foxmask/joplin-api: Joplin API
:wink:

from joplin_api import JoplinApi

#https://discourse.joplin.cozic.net/t/joplin-api-python/1359
joplin = JoplinApi(token='MYTOKEN')
joplin.ping()  # to check if the service is up
joplin.get_folders() # to get all the folders

folder_title = 'Default'
folder = joplin.create_folder(folder_title) # to create a folder
# to create a new note
note_title = 'My title'
note_body = '# My Title ## My Subtitle my body'
joplin.create_note(note_title, note_body, folder['id'])
joplin.get_notes() # to get all the notes
joplin.get_tags() # to get all the tags
joplin.version() # to get the version of joplin
joplin.version()

this does not work at all, this has been removed from the API.
I made a mistake in the README :slight_smile: I fixed it.

>>> folder = joplin.create_folder(folder_title) # to create a folder
>>> folder_id = folder.json()['id']
>>> # to create a new note
>>> note_title = 'My title'
>>> note_body = '# My Title ## My Subtitle my body'
>>> joplin.create_note(note_title, note_body, folder_id)
>>> joplin.get_notes() # to get all the notes
>>> joplin.get_tags() # to get all the tags

this will be better

If you want to test all the API, you can run python test.py also this will create a couple of folders, notes in that created folder, and tags. All of this that can be removed once tests is ran, by dropping the created folders and tags.

Used script:

from joplin_api import JoplinApi

#https://discourse.joplin.cozic.net/t/joplin-api-python/1359
joplin = JoplinApi(token='MYTOKEN')
joplin.ping()  # to check if the service is up
joplin.get_folders() # to get all the folders

folder_title = 'Default'
folder = joplin.create_folder(folder_title) # to create a folder
folder_id = folder.json()['id']
# to create a new note
note_title = 'My title'
note_body = '# My Title ## My Subtitle my body'
joplin.create_note(note_title, note_body, folder_id)
joplin.get_notes() # to get all the notes
joplin.get_tags() # to get all the tags

Output from python:

Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
=================== RESTART: H:\Dropbox\400 - Scriptprogrammierung\Python3\Joplin\JoplinAPI_Uwe.py ===================
method get path http://127.0.0.1:41184/ping/ params {'token': 'MYTOKEN'} payload {} headers {'Content-Type': 'application/json'}
Response of WebClipper <Response [200]>
method get path http://127.0.0.1:41184/folders/ params {'token': 'MYTOKEN'} payload {} headers {'Content-Type': 'application/json'}
Response of WebClipper <Response [200]>
method post path http://127.0.0.1:41184/folders/ params {'token': 'MYTOKEN'} payload {'title': 'Default', 'parent_id': 0} headers {'Content-Type': 'application/json'}
Response of WebClipper <Response [200]>
method post path http://127.0.0.1:41184/notes/ params {'token': 'MYTOKEN'} payload {'title': 'My title', 'body': '# My Title ## My Subtitle my body', 'parent_id': '241a8a1a54f74375bb5cdcb4ac7b5099', 'author': '', 'source_url': '', 'tags': '', 'is_todo': ''} headers {'Content-Type': 'application/json'}
Response of WebClipper <Response [200]>
method get path http://127.0.0.1:41184/notes/ params {'token': 'MYTOKEN'} payload {} headers {'Content-Type': 'application/json'}
Response of WebClipper <Response [200]>
method get path http://127.0.0.1:41184/tags/ params {'token': 'MYTOKEN'} payload {} headers {'Content-Type': 'application/json'}
Response of WebClipper <Response [200]>
>>> 

Output from cmd:

H:\Dropbox\400 - Scriptprogrammierung\Python3\Joplin>python JoplinAPI_Uwe.py
method get path http://127.0.0.1:41184/ping/ params {'token': 'MYTOKEN'} payload {} headers {'Content-Type': 'application/json'}
Response of WebClipper <Response [200]>
method get path http://127.0.0.1:41184/folders/ params {'token': 'MYTOKEN'} payload {} headers {'Content-Type': 'application/json'}
Response of WebClipper <Response [200]>
method post path http://127.0.0.1:41184/folders/ params {'token': 'MYTOKEN'} payload {'title': 'Default', 'parent_id': 0} headers {'Content-Type': 'application/json'}
Response of WebClipper <Response [200]>
method post path http://127.0.0.1:41184/notes/ params {'token': 'MYTOKEN'} payload {'title': 'My title', 'body': '# My Title ## My Subtitle my body', 'parent_id': '48e2428c973e420699c9a2036b7cc0af', 'author': '', 'source_url': '', 'tags': '', 'is_todo': ''} headers {'Content-Type': 'application/json'}
Response of WebClipper <Response [200]>
method get path http://127.0.0.1:41184/notes/ params {'token': 'MYTOKEN'} payload {} headers {'Content-Type': 'application/json'}
Response of WebClipper <Response [200]>
method get path http://127.0.0.1:41184/tags/ params {'token': 'MYTOKEN'} payload {} headers {'Content-Type': 'application/json'}
Response of WebClipper <Response [200]>

H:\Dropbox\400 - Scriptprogrammierung\Python3\Joplin>
1 Like

At the next weekend I can furthermore test your windows releases, if you want.

1 Like

it's nice from you, but use it only if you need it. I don't specially need test :slight_smile:

Can this perform exports and imports?

The API does not provide that, and you don’t need that as you have the direct access to your data under your elbow with it. Look at https://joplin.cozic.net/api/ to check out

I do not know js I know a bit of Python so I was hoping to automate some file conversion and savings, that is why.

1 Like

there is no JS implementation of the API describes at https://joplin.cozic.net/api/ , I just made one for Python.
If you want to automate file conversion then note creation, you can do it with the terminal command line as I spotted a mistake in my implem :wink:

The Python API has methods update_folder and rename_folder.
Basically, rename is update of the title only so the latter method is superfluous.
Also, the rename method uses PUT to /folders, which is not documented in the Joplin API.