# Add a domain

`POST https://api.mailmasker.org/api/v1/domains`

Start serving a domain, for mail, DNS or both.

- Who can use it: Site admins
- Area: Domains and DNS
- Answers 201 Created when it works
- Page: https://developer.mailmasker.org/domain-add

Unless you say otherwise, mail for the domain is accepted from now on and it gets a DNS zone here. A zone that already exists is kept as it is.

## Parameters

| Name | In | Required | What it is | Example |
|---|---|---|---|---|
| `domain_name` | body | yes | The domain, in lowercase. | `example.com` |
| `mail_enabled` | body | no | Accept mail for it. true if left out; false for DNS only. |  |
| `dns_managed` | body | no | Keep its DNS zone here, creating the zone if needed. true if left out; false for mail only. |  |
| `nameservers` | body | no | The name servers for a new zone, as a list. If left out, the zone's name server is `ns-test.` followed by the domain. |  |

## Good to know

- A domain that is already listed answers 409.
- If the DNS zone can't be created, the answer is 502 and the domain isn't added.

## Examples

cURL:

```bash
curl -s -X POST 'https://api.mailmasker.org/api/v1/domains' \
  -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{"domain_name":"example.com"}'
```

Perl:

```perl
use Mojo::Base -strict;
use Mojo::UserAgent;

my $ua  = Mojo::UserAgent->new;
my $res = $ua->post('https://api.mailmasker.org/api/v1/domains',
    { Authorization => "Bearer $ENV{TOKEN}" },
    json => { domain_name => 'example.com' })->result;
die $res->code, ' ', ($res->json('/error') // $res->message), "\n" unless $res->is_success;
print $res->body, "\n";
```

homelab-cli:

```bash
homelab-cli dns domains add example.com
```

## Response

201 Created:

```json
{
  "id": 3,
  "domain_name": "example.com",
  "mail_enabled": 1,
  "dns_managed": 1,
  "active": 1,
  "created_by": "you@example.com",
  "created_at": "2026-11-03 21:42:10.123456-06",
  "updated_at": "2026-11-03 21:42:10.123456-06"
}
```
