Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ Domain Name Service/ API Reference/ Examples/ Example 1: Creating a Public Zone

Example 1: Creating a Public Zone

Updated on 2024-12-20 GMT+08:00

Scenarios

After you register a domain name and set up a website, create a public zone and configure records to point the domain name to the IP address of the web server where the website is deployed so that visitors can use the domain name to access your website over the Internet.

This topic describes how to create a public zone by calling the API in Creating a Public Zone and create a record set by calling the API in Creating a Record Set. For details about how to call APIs, see Calling APIs.

NOTE:

The token obtained from IAM is valid for only 24 hours. If you want to use one token for authentication, you can cache it to avoid frequently calling the IAM API.

Prerequisites

  • You have registered domain name example.com with a third-party registrar.
  • You have deployed a web server and obtained its IP address.

Involved APIs

You need to obtain a token and add X-Auth-Token to the request header of API calls.

  • IAM API for obtaining a token
  • DNS API for creating a public zone
  • DNS API for creating a record set

Procedure

  1. Obtain the token by referring to Authentication and Authorization.
  2. Add Content-Type and X-Auth-Token in the request header.
  3. Specify the following parameters in the request body:
    {
        "name": "example.com.",  // Zone name (mandatory, string)
        "description": "This is an example zone.", // Description of the zone (optional, string)
         "zone_type": "public", // Zone type (optional)
         "email": "xx@example.org" // Email address of the domain name administrator (optional, string)
        "ttl": 300, // Default caching duration of the SOA record (optional, string)
    }
  4. Send a request POST https://DNS endpoint/v2/zones.
  5. Check the response.
    NOTE:
    • The request result may be successful or failed in the response.
    • If the request fails, an error code and error information are returned. For details, see Error Codes.
    • For details about parameters in the response, see Creating a Public Zone.
    • For details about general return codes in the response, see Status Code.

    The following is an example response of a successful request:

    STATUS CODE 202
    {
        "id": "2c9eb155587194ec01587224c9f90149",
        "name": "example.com.",
        "description": "This is an example zone.",
        "email": "xx@example.com",
        "ttl": 300,
        "serial": 1,
        "masters": [],
        "status": "PENDING_CREATE",
        "links": {
            "self": "https://Endpoint/v2/zones/2c9eb155587194ec01587224c9f90149"
        },
        "pool_id": "00000000570e54ee01570e9939b20019",
        "project_id": "e55c6f3dc4e34c9f86353b664ae0e70c",
        "zone_type": "public",
        "created_at": "2016-11-17T11:56:03.439",
        "updated_at": null,
        "record_num": 0
    }
    
  6. Add Content-Type and X-Auth-Token in the request header.
  7. Specify the following parameters in the request body:
    {
        "name": "example.com.",  // Zone name (mandatory, string)
        "description": "This is an example record set.", // Description of the record set (optional, string)
         "type": "A", // Record set type (mandatory, string)
        "ttl": 3600, // Caching duration of the record set (optional, integer)
        "records": [ 
            "192.168.10.1", 
            "192.168.10.2"
         ] // Values of the record set (mandatory, list<string>)
    }
  8. Send a request POST https://DNS endpoint/v2/zones/{zone_id}/recordsets, where zone_id is the ID of the zone to which the record set is to be added.
  9. Check the response.
    STATUS CODE 202
    {
        "id": "2c9eb155587228570158722b6ac30007",
        "name": "example.com.",
        "description": "This is an example record set.",
        "type": "A",
        "ttl": 300,
        "records": [
            "192.168.10.1",
            "192.168.10.2"
        ],
        "status": "PENDING_CREATE",
        "links": {
            "self": "https://Endpoint/v2/zones/2c9eb155587194ec01587224c9f90149/recordsets/2c9eb155587228570158722b6ac30007"
        },
        "zone_id": "ff8080825b8fc86c015b94bc6f8712c3",
        "zone_name": "example.com.",
        "create_at": "2017-04-22T08:17:08.997",
        "update_at": null,
        "default": false,
        "project_id": "e55c6f3dc4e34c9f86353b664ae0e70c"
    }

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback