# Register new domain

{% tabs %}
{% tab title="Shell" %}

```sh
curl https://api.acymailer.com/api/createDomainIdentity \
 -X POST
 -H 'Content-Type: application/json' \
 -H 'API-KEY: your-license-key' \
 -H 'Version: external' \
 -d '{"domain": "example.com","siteUrl": "https://example.com"}'
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
  
$acymailer = new AcyMailer\SendingService('your-license-key');

$domain = $acymailer->addDomain('example.com');
```

{% endtab %}

{% tab title="Node" %}

```javascript
import {AcyMailer} from '@acymailing/sending-service';

const mailer = new AcyMailer('your-license-key');

const domain = await mailer.addDomain({name: 'example.com'});
```

{% endtab %}
{% endtabs %}

<mark style="color:green;">`POST`</mark> `/api/createDomainIdentity`

This endpoint allows you to register a new domain identity to send email with

**Headers**

| Name         | Value                |
| ------------ | -------------------- |
| Content-Type | `application/json`   |
| API-KEY      | `<license-key>`      |
| Version      | `Must be "external"` |

**Body**

```json
{
    "domain": "example.com",
    "siteUrl": "https://example.com"
}
```

* **domain** must be your root domain, if you register a subdomain it won't work.
* **siteUrl** must be https\://\<your-domain>, even if you don't have a website at this address

**Response**

{% tabs %}
{% tab title="200: Already Exist" %}

```json
{
  "code": 9,
  "message": "Identity created",
  "cnameRecords": [
    {
      "name": "2qsv5cnrrzscxcz2otmdlgnkxu3f7wpv._domainkey.example.com",
      "type": "CNAME",
      "value": "2qsv5cnrrzscxcz2otmdlgnkxu3f7wpv.dkim.acymailer.com"
    },
    {
      "name": "4rngy5xnrec3qmwotcr6p7whqi7ig46z._domainkey.example.com",
      "type": "CNAME",
      "value": "4rngy5xnrec3qmwotcr6p7whqi7ig46z.dkim.acymailer.com"
    },
    {
      "name": "tokt23mkvo5cqtgk3vgpmdy6toscp4uh._domainkey.example.com",
      "type": "CNAME",
      "value": "tokt23mkvo5cqtgk3vgpmdy6toscp4uh.dkim.acymailer.com"
    }
  ]
}
```

{% endtab %}

{% tab title="201: Created" %}

```json
{
  "code": 9,
  "message": "Identity created",
  "cnameRecords": [
    {
      "name": "2qsv5cnrrzscxcz2otmdlgnkxu3f7wpv._domainkey.example.com",
      "type": "CNAME",
      "value": "2qsv5cnrrzscxcz2otmdlgnkxu3f7wpv.dkim.acymailer.com"
    },
    {
      "name": "4rngy5xnrec3qmwotcr6p7whqi7ig46z._domainkey.example.com",
      "type": "CNAME",
      "value": "4rngy5xnrec3qmwotcr6p7whqi7ig46z.dkim.acymailer.com"
    },
    {
      "name": "tokt23mkvo5cqtgk3vgpmdy6toscp4uh._domainkey.example.com",
      "type": "CNAME",
      "value": "tokt23mkvo5cqtgk3vgpmdy6toscp4uh.dkim.acymailer.com"
    }
  ]
}
```

{% endtab %}

{% tab title="404" %}

```json
{
    "code": 19,
    "message": "License not found for this API key"
}
```

{% endtab %}

{% tab title="400" %}

```json
{
    "code": 17,
    "message": "Missing arguments"
}
```

{% endtab %}

{% tab title="403" %}

```json
{
    "code": 11,
    "message": "The domain already exists and it doesn\'t belong to you."
}
```

{% endtab %}

{% tab title="403" %}

```json
{
    "code": 27,
    "message": "You can attach a domain to only one of your licenses."
}
```

{% endtab %}

{% tab title="422" %}

```json
{
    "code": 0,
    "message": "The domain is not valid"
}

{
    "code": 25,
    "message": "An error occurred, see details in the sending service logs file in the configuration"
    "logs": "Message error"
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.acymailing.com/acymailer/domains/register-new-domain.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
