`lumail@2.1.0` · [`lumail.domains`](/docs/sdk/v2/domains)

```typescript
domains.create({ domain: string }): Promise<LumailResult<DomainRecord>>
```

Registers the domain and returns DNS records.

## Body Parameters

| Name | Type | Description |
| -------- | ------ | ------------------------------------------------------- |
| `domain` | string | **Required.** Hostname to register as a sending domain. |

## Response Fields

| Field | Type | Description |
| ------------ | --------- | ------------------------------------- |
| `id` | string | Domain id. |
| `domain` | string | Hostname. |
| `status` | string | Usually `PENDING` until DNS verifies. |
| `region` | string | Optional SES region. |
| `createdAt` | string | Optional ISO 8601 timestamp. |
| `sesRecords` | unknown | Optional provider DNS payload. |
| `dnsRecords` | unknown[] | Records to publish at your DNS host. |
| `message` | string | Optional status note. |

`data` is the domain record. Failures return `{ data: null, error: { name, message, statusCode } }`.


## API Reference
**Method:** POST
**Endpoint:** /api/v2/domains

### SDK
```ts
import { Lumail } from "lumail";

const lumail = new Lumail({ apiKey: process.env.LUMAIL_API_KEY });
const { data, error } = await lumail.domains.create({
  domain: "mail.example.com",
});
if (error) {
  throw error;
}
console.log(data.id, data.dnsRecords);
```

### cURL
```bash
curl -X POST https://lumail.io/api/v2/domains \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"domain":"mail.example.com"}'
```

### JavaScript
```javascript
const response = await fetch("https://lumail.io/api/v2/domains", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_API_TOKEN",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ domain: "mail.example.com" }),
});
const data = await response.json();
```

### Success Response
```json
{
  "id": "dom_abc123",
  "domain": "mail.example.com",
  "status": "PENDING",
  "dnsRecords": [
    { "type": "CNAME", "name": "abc._domainkey.mail.example.com", "value": "abc.dkim.amazonses.com" }
  ]
}
```

### Error Response
```json
{
  "name": "validation_error",
  "message": "Domain already registered",
  "statusCode": 422
}
```
