Home / GitHub Page

Joplin API - Python

Its because, before the api was released i wrapped the terminal command line which allow to rename folder, so i didnt remove it :nerd_face:

Hello!
I have a problem with API with sample from docs:

Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from joplin_api import JoplinApi
>>> joplin = JoplinApi(token='MY_TOKEN')
>>> joplin.ping()
<coroutine object JoplinApi.ping at 0x0373A810>
>>> folder = joplin.create_folder('folder_title')
>>> folder_id = folder.json()['id']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'coroutine' object has no attribute 'json'
>>>

After that got error and in Jolpin not exist new folder.
Version: Joplin 1.0.161, Win10 x64, Python 3.7.4. In Jolpin enabled clipper.

What I am doing wrong ?

You made a mistake.
Doc says

>>> from joplin_api import JoplinApi
>>> joplin = JoplinApi(token='the token provided by Joplin in the WebClipper menu:P'))
>>> ping = await joplin.ping()  # to check if the service is up
>>> print(ping.text)

You will notice the await keyword

If I add await, i have another error:

Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
>>> from joplin_api import JoplinApi
>>> joplin = JoplinApi(token=MY_TOKEN)
>>> ping = await joplin.ping()
  File "<stdin>", line 1
SyntaxError: 'await' outside function

Search in internet: when use ‘async’, ‘await’ needed ‘event loop’.
I am confused, what i need to do

This should answer your questions https://github.com/foxmask/joplin-api/issues/4
I will improve the doc with the event loop

@foxmask I somehow doubt that using an event loop for a request API makes sense. while this could be great for your web project, it’s rather awkward for using the API in a simple python script or on the command line. Maybe I’m wrong, but this seems excessive to me.

@tessus this is how asyncio works

@mrkingmidas with python 3.7+ you can use

asyncio.run(main())

instead of using the event loop by hand.
run is like a shortcut for it.

I underatand that, but what I’m saying is that it is not necessary to use asyncio for this API. At least not when using it in a script or when I quickly want to fire off a quick python code on the command line.

In that case it’s better to wrap the Joplin command line