These instructions will allow you to change your google apps for business primary domain without writing an code...
- Open this page in a new tab: https://developers.google.com/admin-sdk/directory/v1/reference/customers/update
- Click Try It
- Make sure you’re logged into your relevant Google account (you should see your mail address in the top right corner).
- Next to customerKey type: my_customer
- Next to fields type: customerDomain