Get tag ID by name?

I’m probably missing something obvious. In my plugin, I need to ensure a note has the tag ‘X’.

I can do:

const tagObj = await joplin.data.post(['tags'], null, { title: tag });
await joplin.data.post(['tags', tagObj.id, 'notes'], null, { id: noteId });

which works when the tag does not exist yet.
I see the method for data.get which seems to take a "query" parameter; but I haven't been able to make it work with any query I tried, I always got all the tags back; same with the 'search' endpoint.

Can anybody tell me what am I doing wrong?

I don't think there's a way to do this so you'd have to fetch all the tags to find the one you're interested in.

It should be possible to get the tag from the search endpoint (see python script).

Python script
from joppy.client_api import ClientApi

# Create a new Api instance.
api = ClientApi(token=TOKEN)

# create tag
id_created = api.add_tag(title="abc")

# search for tag
search_results = api.search_all(query="abc", type="tag")
assert len(search_results) == 1
id_searched = search_results[0].id

# verify that the correct tag was found
assert id_created == id_searched
print(id_searched)

# cleanup
api.delete_tag(id_searched)

Something confusing is that the query of the search endpoint is not the search query itself. I.e. the request to the search endpoint should look similar to this pseudocode: path=/search, query={'query': 'abc', 'type': 'tag'}.

Thanks to you both