To follow on what @MichaelOjeda said, once you have an API Token, the curl request to add a domain via the API is:
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer APITOKEN" -d '{"name":"example.com","ip_address":"1.2.3.4"}' "https://api.digitalocean.com/v2/domains"
For NEW droplets, you can automate this by pasting a user-data cloud-config script in the User Data field on the Droplet Create page:
#cloud-config
runcmd:
- export DROPLET_NAME=$(curl -s http://169.254.169.254/metadata/v1/hostname)
- export DROPLET_IP=$(curl -s http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/address)
- 'curl -X POST -H ''Content-Type: application/json'' -d ''{"name":"''"$DROPLET_NAME"''.example.com", "ip_address":"''"$DROPLET_IP"''"}'' -H "Authorization: Bearer API_TOKEN" https://api.digitalocean.com/v2/domains'
replace example.com and API_TOKEN
The #cloud-config
line specifies that you are using cloud-init language (which interprets this as YAML), runcmd:
specifies that the following lines should be run in shell when server first starts.
The two export lines set the droplet’s IP address and name as environment variables, and the final line makes the HTTP request to create a new domain via the API.
(All the extra quotation marks are due to making YAML and JSON play nice together)

by Justin Ellingwood
The DigitalOcean metadata service includes a field called "user-data", which can be used to specify a script that will be run as your server is brought online. The CloudInit program, which runs these scripts, can process a special script type called "cloud-config". In this guide, we'll explore how to create cloud-config files and the best ways to leverage their power.