Help Center/ Content Delivery Network/ API Reference/ Examples/ Adding an Acceleration Domain Name
Updated on 2024-05-16 GMT+08:00

Adding an Acceleration Domain Name

Description

This section describes how to add an acceleration domain name using an API. For details about how to call APIs, see Calling APIs.

Constraints

  • CDN has been enabled for your HUAWEI ID.
  • The API cannot be used to add acceleration domain names in batches.

Involved APIs

  • If you use token-based authentication, obtain a token and add X-Auth-Token to the request header when calling an API.
  • Creating a Domain Name

Procedure

  1. Obtain a user token and use it for authentication when calling the API for adding an acceleration domain name. For details, see Making an API Request.
    • To obtain the username and domain name, log in to the Huawei Cloud management console, point to the account name in the upper right corner, and choose My Credentials from the drop-down list.
    • Request URL: POST https://iam.myhuaweicloud.com/v3/auth/tokens
    • Request header: Content-Type: application/json
    • Request body:
      {
      	"auth": {
      	"identity": {
      		"methods": ["password"],
      		"password": {
      			"user": {
      				"name": "name",           --Username
      				"password": "password",       --Password
      				"domain": {
      					"name": "domainname"    --Name of the account to which the user belongs
      				}
      			}
      		}
      	},
      	"scope": {
      			"domain": {
      				"name": "domainname"    --Name of the account to which the user belongs
      		}
      		}
      	}
        }

    Information in the red box in Figure 1 indicates the obtained user token.

    Figure 1 Obtaining a user token
  2. Select the POST request method and enter the request URI.
    POST  https://cdn.myhuaweicloud.com/v1.0/cdn/domains
  3. Add X-Auth-Token to the request header. The value of X-Auth-Token is the value of x-subject-token in the header of the respond to the authentication request, as shown in the red box in Figure 1.
  4. Specify the following parameters in the request body:
    {
        "domain": {
            "domain_name": "example1.example2.example3.com",
            "business_type": "web",
            "sources": [
                {
                    "ip_or_domain": "192.168.53.75",
                    "origin_type": "ipaddr",
                    "active_standby":1
                }
            ],
        }
    }

    If the request is successful, information about the created domain name is returned.

    {
        "domain": {
            "sources": [
                {
                    "domain_id":"ff80*************************07b",
                    "ip_or_domain": "192.168.53.75",
                    "origin_type": "ipaddr",
                    "active_standby":1
                }
            ],
            "id": "ff80*************************07b",
            "user_domain_id": "38***********************5024dcb",
            "domain_name": "example11.example2.example3.com",
            "business_type": "web",
            "cname": "example1.example2.example3.com.c.example4.com",
            "domain_status": "configuring",
            "https_status": null,
            "description": null,
            "create_time": 1513152634467,
            "modify_time": 1513152634467,
            "domain_origin_host": {
                "domain_id": "ff80*************************07b",
                "origin_host_type": "customize",
                "customize_domain": "example5.example6.com"
            },
            "disabled": 0,
            "locked": 0
        }
    }

    If the request fails, an error code and error information are returned. For details, see Error Codes.