Strangly this does not work for pages that have sub sections.
Using this, the APi outputs 1, 1.1, 1.2, 2, 3, 4 etc
Were the API expects it would just be 1, 2, 3, 4, 5, 6 (treating sub sections as full sections).
Hmm...
http://example.com/api.php?action=parse&text=%7B%7B:Main Page}}__TOC__&prop=sections
Should do it. Replace the text "Main Page" in the example with the actual name of the page you're interested in.
Mike