Joplin's data API has a search endpoint to get the note ID. I'm not certain if this ID is what you want, since unique key sounds like you are operating on the database directly. But maybe it's the same.
Alternatively, depending on how you determine duplicates, you could use joppy for example. The script could look like:
Iterate over all notes (including the ID): for note in get_all_notes(fields="title,id,body")
Yes, that sounds reasonable. You could even avoid writing to the filesystem if your algorithm works in Python. Title, body and ID of the notes are all available in-memory as part of the note object (note.title, note.id and note.body).