I want to apply (org-id-get-create) to every top-level heading in the buffer. How can I loop through all top-level org-mode headings in the current buffer?
You can use
org-map-entries to apply a function to all the entries in a org-mode buffer matching a search. In this case the search "LEVEL=1" will match all top level headlines. The function you specify will be called without arguments with the point on the headline. So
(org-map-entries 'org-id-get-create "LEVEL=1") will apply the
org-id-get-create function to every
LEVEL 1 headline.