Is not that what the id property about?
In what form are you exporting the pages?
I'm not sure, but I guess the workflow of the OP is Export to EPUB or HTML.
And unfortunately the ids that are created during the export process have nothing in common with the ids for page items we see in an InDesign document.
One example showing exported IDs for e.g. Publish Online HTML:
<div id = "_idContainer000" class="Einfacher-Textrahmen"
<div id = "_idContainer000" class="Basic-Text-Frame"
And is not following InDesign's pageItem id numbering and object naming system.
Made up scheme:
<div id = "_356" class="TextFrame"
For some objects that hold transparency even new objects are created that never existed in the InDesign document.
It's hard to foresee what survives how when exported and if e.g. tagging with e.g. alt text would go unaltered through the workflow.
I think I've figured this out now - the "label" property does what we need. I can set a metadata value programmatically by selecting an item (e.g. text frame)
app.selection.label = 'some label';
And we can confirm the value in the InDesign GUI by selecting the labeled object and clicking on Window > Utilities > Script Label.
If we use comma separated values, we can store multiple items of metadata here.