This topic describes how to use a developer tool, such as Alibaba Cloud CLI, OpenAPI Explorer, or an Alibaba Cloud SDK, to call the API operations of Alibaba Cloud Domain Name System (DNS).
Use Alibaba Cloud CLI to call the API operations of Alibaba Cloud DNS
Before you use this method, make sure that you have installed and configured Alibaba Cloud CLI.
The following examples show how to use Alibaba Cloud CLI to call the following API operations:
AddDomainRecord
UpdateDomainRecord
DescribeDomainRecords
DescribeSubDomainRecords
Before you call an API operation, you must understand the related instructions provided in API Reference and obtain the values of the required request parameters. If an error occurs when you call an API operation, you can view the troubleshooting suggestions in the related topic.
Call the AddDomainRecord operation to add a DNS record.
Call the UpdateDomainRecord operation to modify a DNS record. In this example, the hostname is changed from apitest3 to apitest4.
Call the DescribeDomainRecords operation to query all DNS records of the domain name ddnstest.top.
Call the DescribeSubDomainRecords operation to query all DNS records of the subdomain name apitest.dns-example.com.
Call the DescribeSubDomainRecords operation to query all DNS records of a subdomain name.
Use OpenAPI Explorer to call the API operations of Alibaba Cloud DNS
The following example shows how to use OpenAPI Explorer to call the AddDomainRecord operation. For more information about OpenAPI Explorer, see What is OpenAPI Explorer?
The following are the five Alibaba Cloud DNS API operations that are most frequently called by using OpenAPI Explorer:
AddDomainRecord: adds a DNS record based on input parameters.
UpdateDomainRecord: modifies a DNS record based on input parameters.
DescribeDomainRecords: queries all DNS records of a specified domain name based on input parameters.
DescribeSubDomainRecords: queries all DNS records of a specified subdomain name based on input parameters.
DescribeDomainRecordInfo: queries the details about a DNS record based on input parameters.
The following figures show how to call the AddDomainRecord operation and the sample results.
Use Alibaba Cloud SDK for Java to call the API operations of Alibaba Cloud DNS
The following example shows how to use Alibaba Cloud SDK for Java to call the AddDomainRecord operation. For information about how to configure Alibaba Cloud SDKs, see SDK.
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;
import java.util.*;
import com.aliyuncs.alidns.model.v20150109.*;
public class AddDomainRecord {
public static void main(String[] args) {
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<accessKeyId>", "<accessSecret>");
IAcsClient client = new DefaultAcsClient(profile);
AddDomainRecordRequest request = new AddDomainRecordRequest();
request.setValue("3.0.3.0");
request.setType("A");
request.setRR("apitest");
request.setDomainName("dns-example.com");
try {
AddDomainRecordResponse response = client.getAcsResponse(request);
System.out.println(new Gson().toJson(response));
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
System.out.println("ErrCode:" + e.getErrCode());
System.out.println("ErrMsg:" + e.getErrMsg());
System.out.println("RequestId:" + e.getRequestId());
}
}
}
Use Alibaba Cloud SDK for Node.js to call the API operations of Alibaba Cloud DNS
The following example shows how to use Alibaba Cloud SDK for Node.js to call the AddDomainRecord operation.
const Core = require('@alicloud/pop-core');
var client = new Core({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessSecret>',
endpoint: 'https://alidns.aliyuncs.com',
apiVersion: '2015-01-09'
});
var params = {
"DomainName": "dns-example.com",
"RR": "apitest1",
"Type": "A",
"Value": "3.0.3.0"
}
var requestOption = {
method: 'POST'
};
client.request('AddDomainRecord', params, requestOption).then((result) => {
console.log(JSON.stringify(result));
}, (ex) => {
console.log(ex);
})
Use Alibaba Cloud SDK for Go to call the API operations of Alibaba Cloud DNS
The following example shows how to use Alibaba Cloud SDK for Go to call the AddDomainRecord operation.
package main
import (
"fmt"
"github.com/aliyun/alibaba-cloud-sdk-go/services/alidns"
)
func main() {
client, err := alidns.NewClientWithAccessKey("cn-hangzhou", "<accessKeyId>", "<accessSecret>")
request := alidns.CreateAddDomainRecordRequest()
request.Scheme = "https"
request.Value = "3.0.3.0"
request.Type = "A"
request.RR = "apitest1"
request.DomainName = "dns-example.com"
response, err := client.AddDomainRecord(request)
if err != nil {
fmt.Print(err.Error())
}
fmt.Printf("response is %#v\n", response)
}
Use Alibaba Cloud SDK for PHP to call the API operations of Alibaba Cloud DNS
The following example shows how to use Alibaba Cloud SDK for PHP to call the AddDomainRecord operation.
<?php
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
// Download URL: https://github.com/aliyun/openapi-sdk-php
// User guide: https://github.com/aliyun/openapi-sdk-php/blob/master/README.md
AlibabaCloud::accessKeyClient('<accessKeyId>', '<accessSecret>')
->regionId('cn-hangzhou') // replace regionId as you need
->asDefaultClient();
try {
$result = AlibabaCloud::rpc()
->product('Alidns')
// ->scheme('https') // https | http
->version('2015-01-09')
->action('AddDomainRecord')
->method('POST')
->options([
'query' => [
'DomainName' => "dns-example.com",
'RR' => "apitest1",
'Type' => "A",
'Value' => "3.0.3.0",
],
])
->request();
print_r($result->toArray());
} catch (ClientException $e) {
echo $e->getErrorMessage() . PHP_EOL;
} catch (ServerException $e) {
echo $e->getErrorMessage() . PHP_EOL;
}
Use Alibaba Cloud SDK for Python to call the API operations of Alibaba Cloud DNS
The following example shows how to use Alibaba Cloud SDK for Python to call the AddDomainRecord operation.
#!/usr/bin/env python
#coding=utf-8
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkalidns.request.v20150109.AddDomainRecordRequest import AddDomainRecordRequest
client = AcsClient('<accessKeyId>', '<accessSecret>', 'cn-hangzhou')
request = AddDomainRecordRequest()
request.set_accept_format('json')
request.set_Value("3.0.3.0")
request.set_Type("A")
request.set_RR("apitest1")
request.set_DomainName("dns-example.com")
response = client.do_action_with_exception(request)
# python2: print(response)
print(str(response, encoding='utf-8'))
Use Alibaba Cloud SDK for .NET to call the API operations of Alibaba Cloud DNS
The following example shows how to use Alibaba Cloud SDK for .NET to call the AddDomainRecord operation.
using System;
using System.Collections.Generic;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Alidns.Model.V20150109;
namespace AlidnsDemo
{
class Program{
static void Main(string[] args){
IClientProfile profile = DefaultProfile.GetProfile("cn-hangzhou", "<accessKeyId>", "<accessSecret>");
DefaultAcsClient client = new DefaultAcsClient(profile);
var request = new AddDomainRecordRequest();
request.Value = "3.0.3.0";
request.Type = "A";
request.RR = "apitest1";
request.DomainName = "dns-example.com";
try {
var response = client.GetAcsResponse(request);
Console.WriteLine(System.Text.Encoding.Default.GetString(response.HttpResponse.Content));
}
catch (ServerException e){
Console.WriteLine(e);
}
catch (ClientException e){
Console.WriteLine(e);
}
}
}
}
Use Alibaba Cloud SDK for Ruby to call the API operations of Alibaba Cloud DNS
The following example shows how to use Alibaba Cloud SDK for Ruby to call the AddDomainRecord operation.
# gem install aliyunsdkcore
require 'aliyunsdkcore'
client = RPCClient.new(
access_key_id: '<accessKeyId>',
access_key_secret: '<accessSecret>',
endpoint: 'https://alidns.aliyuncs.com',
api_version: '2015-01-09'
)
response = client.request(
action: 'AddDomainRecord',
params: {
"DomainName": "dns-example.com",
"RR": "apitest1",
"Type": "A",
"Value": "3.0.3.0"
},
opts: {
method: 'POST'
}
)
print response