Call Table Of Contents Macro Confluence API

Hi,

I’m aggregating some confluence content, in Java, and for the pages I pull in, I’d like to create a Table of Confluence Macro dynamically to match the headers.

I’ve read the Confuence Rest api but didn’t find any calls I could make relevant to my topic. (Maybe I missed something)

Also, I’ve tried to inspect the ToC Macro and paste that information within my code, but that doesn’t work-- the only thing displayed is the image of the ToC Macro you see during Edit mode.

Is this possible, if so how?

Cheers