Get the ID for the default organization through API
The default organization contact id is stored in civicrm_domain table. You can use domain api to retrieve the contact id i.e

  $result = civicrm_api3('Domain', 'getvalue', array(
      'sequential' =&gt; 1,
      'return' =&gt; "contact_id",
      'id' =&gt; 1,
    ));


HTH

Pradeep