Export list of tags

I'm playing around with some autohotkey scripting to do a few things with Joplin and I was hoping to find away to output a listing of tags. what i was trying to do was just use curl to spit out a text file of all of the tags in my data. but evidently my skills on using curl need some work. can anyone give me a hand on using curl? another option would be a short python script to do the same, but curl is preferable.

thanks in advance

There are some curl examples in the API docs

But this way you'd have to deal with pagination, a python might be easier.

thanks, i'm going thru the docs, 1 question is on the required token. does the whole token string need top be in the curl command or can i point to a text file that has the token?

conversely, any one interested in writing a short python script to do this? or point me to a good example?

Alternatively, if you are just after this for a one-off or occasional task and already have the right tools then you could just query the database directly.

Recommend taking a copy of the database first and running the queries on that for safety reasons rather than against the "live" db.

Simply running:

SELECT title
FROM tags

Will get you a list of tags or to bring back a list of tags actually bound to a note (to avoid "dead" tags with no associations).

FROM tags
INNER JOIN note_tags ON tags.id = note_tags.tag_id
ORDER BY tags.title asc;

Or if you want to collate how many notes associate with each tag:

SELECT tags.title, COUNT(tags.title) AS count
FROM tags
INNER JOIN note_tags ON tags.id = note_tags.tag_id
GROUP BY tags.title
ORDER BY tags.title ASC;

You could use joppy. To get all tags, the workflow would be like:

  1. Enable the webclipper service in joplin and copy the token
  2. pip install joppy
  3. export API_TOKEN="YOUR_API_TOKEN" or the equivalent windows command
  4. Execute the following script:
import os
from joppy.api import Api

api = Api(token=os.getenv("API_TOKEN"))
all_tags = api.get_all_tags()

Alternatively, the token could be stored in a text file, too if you prefer.


thanks @Daeraxa, for what I am doing, I need the tags in a text file outside of joplin.

thanks @Marph, I didn't know of joppy so i'll take a look. you mentioned that the token could be stored in a text file. i'm assuming the 'os.getenv' statement will need to do a file read function?

Still entirely possible, with a GUI tool you just copy and paste the query result and with a CLI tool you just pipe it to csv or whatever you want.

os.getenv() reads from the environment. Imo. it's a bit more convenient.

If you want to read the token from a file and the results to a file, it could look like:

from joppy.api import Api

with open("joplin_api_token.txt") as infile:
    token = infile.read()
api = Api(token=token)
all_tags = api.get_all_tags()

with open("all_tags.txt", "w") as outfile:
    outfile.write("\n".join(tag["title"] for tag in all_tags))