# CreateDomain

## 1. API Description

This API (CreateDomain) is used to create an accelerated domain.

#### Preparation

* Query the business types for accelerated domains: Call [`DescribeBusinessTypes`](/api/networking/cdn/common/describebusinesstypes.md).
* Query the acceleration regions for accelerated domains: Call [`DescribeAccelerationRegions`](/api/networking/cdn/common/describeaccelerationregions.md).

{% hint style="info" %}
**Notes**

* The `domain` must be globally unique and cannot be duplicated.
* The `domainName` must not be the same as the origin, as this will create a loop and prevent acceleration from working.
* This is an asynchronous API. After a successful request, the creation of the accelerated domain is not immediately complete. During this period, the status of the accelerated domain will be `Deploying`. You can check the status of the accelerated domain by calling the `DescribeCdnDomains` API. If the domain status changes from `Deploying` to `Deployed`, the deployment is successful; if it changes to `Failed`, the configuration failed.
  {% endhint %}

## 2. Request Parameters

The following table lists the required request parameters for this API.

| Parameter Name       | Required | Type                                                  | Description                                                                                                                                                           |
| -------------------- | -------- | ----------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| domainName           | Yes      | String                                                | <p>The accelerated domain</p><p>The domain must be globally unique and cannot be duplicated.</p><p>The domain must not be the same as the origin to avoid looping</p> |
| businessTypeId       | Yes      | String                                                | The business type ID                                                                                                                                                  |
| resourceGroupId      | No       | String                                                | <p>The resource group ID.</p><p>If not provided, the default resource group will be used.</p>                                                                         |
| accelerationRegionId | Yes      | String                                                | The acceleration region ID                                                                                                                                            |
| origin               | Yes      | [Origin](/api/networking/cdn/datastructure.md#origin) | Source information                                                                                                                                                    |

## 3. Output Parameters

| Parameter Name | Type   | Description                                                                     |
| -------------- | ------ | ------------------------------------------------------------------------------- |
| requestId      | String | Unique request ID returned for each request. Provide this when locating issues. |
| domainId       | String | The ID of the accelerated domain.                                               |

## 4. Code Example

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

1. **Create an Accelerated Domain**

```json
POST / HTTP/1.1
Host: console.zenlayer.com/api/v2/cdn
Content-Type: application/json
X-ZC-Action: CreateDomain
<Common Request Params>

Request:
{
    "domainName": "cdntest.zenlayer.com",
    "businessTypeId": "xxx-xx",
    "accelerationRegionId": "xxx-xx",
    "resourceGroupId":"xxx-xx",
    "origin": {
        "masterSource": "1.1.1.1",
        "slaverSource": "2.2.2.2",
        "originPort": "80",
        "originPortHttps": "443"
    }
}

Response:
{
    "requestId": "TEEFDCA5B-76FB-4E91-A18E-DF7F5D2CE41F",
    "response": {
        "requestId": "TEEFDCA5B-76FB-4E91-A18E-DF7F5D2CE41F",
        "domainId": "domainIdxxxxx"
    }
}
```

{% endtab %}
{% endtabs %}

## 5. Error Codes

The following includes error codes encountered in business logic. For other error codes, see [Common Error Codes](/api/api-introduction/instruction/commonerrorcode.md).

| HTTP Status Code | Error Code                                | Description                                             |
| ---------------- | ----------------------------------------- | ------------------------------------------------------- |
| 404              | INVALID\_ACCELERATION\_REGION\_NOT\_FOUND | The specified acceleration region was not found         |
| 404              | INVALID\_BUSINESS\_TYPE\_NOT\_FOUND       | The specified business type was not found               |
| 404              | INVALID\_RESOURCE\_GROUP\_NOT\_FOUND      | The specified resource group was not found              |
| 400              | INVALID\_ORIGIN\_MASTER\_SOURCE           | The master source format is incorrect                   |
| 400              | INVALID\_ORIGIN\_SLAVER\_SOURCE           | The backup source format is incorrect                   |
| 400              | INVALID\_ORIGIN\_SOURCE\_SAME\_AS\_DOMAIN | The origin cannot be the same as the accelerated domain |


---

# 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.console.zenlayer.com/api/networking/cdn/domain/createdomain.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.
