Is it possible to access external links (i.e., the same as right-clicking on a notebook or note and selecting "Copy external link") via the API? I can't find anything on this in the docs so I suspect it currently isn't, but presumably it would be relatively trivial to implement.
The issue is that it needs to work for both notes and notebooks. An external link to a note starts with joplin://x-callback-url/openNote?id= followed by the note id, and a notebook link has openFolder instead of openNote. It's easy enough to automate the creation of the link if there's some way for the automation script or plugin to know whether you're linking to a note or a notebook, but otherwise it's impossible (as far as I can tell). An API solution should resolve that ambiguity, depending on what is selected.
Do I understand you correctly you're looking for a way to create a link having only the id without knowing whether the id refers to a note or a folder or a tag?
I suppose in this case you can just look up the note and if it exists create a note link, same for folder and tag.
Is there a way to get the ID of the selected note or notebook via the API? I can only find methods for retrieving a note and its metadata if you already know the ID.