Example 1: Creating a Public Zone
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.
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
- Obtain the token by referring to Authentication.
- Add Content-Type and X-Auth-Token in the request header.
- 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) }
- Send a request POST https://DNS endpoint/v2/zones.
- Check the response.
- 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 }
- Add Content-Type and X-Auth-Token in the request header.
- 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>) }
- 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.
- 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" }
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot