The Domains service provides software development kits (SDKs) for four programming languages: Java, Python, PHP, and .NET. This topic provides the download links and quick start guides of the SDKs for these languages, and demonstrates the installation and usage of the SDK for Java as an example.

Procedure

This section illustrates how to install and use the Java SDK.
  1. Log on to the Alibaba Cloud official website. Create and manage your AccessKey for your Alibaba Cloud account.
  2. Use Maven to install the SDK.
    1. Create a Maven repository.
      <repositories>
           <repository>
               <id>sonatype-nexus-staging</id>
               <name>Sonatype Nexus Staging</name>
               <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
               <releases>
                   <enabled>true</enabled>
               </releases>
               <snapshots>
                   <enabled>true</enabled>
               </snapshots>
           </repository>
      </repositories>
    2. Add the JAR dependency package.
      Note We recommend that you use the JAR package of the latest version.
      <dependency>
       <groupId>com.aliyun</groupId>
       <artifactId>aliyun-java-sdk-domain-intl</artifactId>
           <version>1.0.0</version>
      </dependency>
      <dependency>
       <groupId>com.aliyun</groupId>
       <artifactId>aliyun-java-sdk-core</artifactId>
           <version>3.5.0</version>
      </dependency>
    3. Check the following sample code. The following code shows how to submit a task of registering multiple domain names at a time:
      import java.util.ArrayList;
      import com.aliyuncs.DefaultAcsClient;
      import com.aliyuncs.IAcsClient;
      import com.aliyuncs.domain_intl.model.v20171218.SaveBatchTaskForCreatingOrderActivateRequest;
      import com.aliyuncs.domain_intl.model.v20171218.SaveBatchTaskForCreatingOrderActivateRequest.OrderActivateParam;
      import com.aliyuncs.domain_intl.model.v20171218.SaveBatchTaskForCreatingOrderActivateResponse;
      import com.aliyuncs.exceptions.ClientException;
      import com.aliyuncs.exceptions.ServerException;
      import com.aliyuncs.profile.DefaultProfile;
      import com.aliyuncs.profile.IClientProfile;
      public class DomainSdkDemo {
          private static IAcsClient client = null;
          // Initialize the client.
          static {
              String regionId = "ap-southeast-1"; // Use the fixed value ap-southeast-1 for the Domains SDKs.
              String accessKeyId = ""; // your accessKey
              String accessKeySecret = "";// your accessSecret
              IClientProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
              // If the message "Can not find endpoint to access" appears, add the following code:
              // DefaultProfile.addEndpoint("ap-southeast-1", "ap-southeast-1", "Domain-intl", "domain-intl.aliyuncs.com");
              client = new DefaultAcsClient(profile);
          }
          public static void main(String[] args) {
              // Initialize the request.
              SaveBatchTaskForCreatingOrderActivateRequest request = new SaveBatchTaskForCreatingOrderActivateRequest();
              // request.setProtocol(ProtocolType.HTTPS); // Specify the protocol.
              // request.setAcceptFormat(FormatType.JSON); // Specify the API response format.
              // request.setMethod(MethodType.POST); // Specify the request method.
              ArrayList<OrderActivateParam> list = new ArrayList<OrderActivateParam>();
              OrderActivateParam orderActivateParam = new OrderActivateParam();
              orderActivateParam.setDomainName("yourdomain.com");
              orderActivateParam.setRegistrantProfileId(0L);
              orderActivateParam.setEnableDomainProxy(false);
              orderActivateParam.setSubscriptionDuration(1);
              orderActivateParam.setPermitPremiumActivation(false);
              list.add(orderActivateParam);
              request.setOrderActivateParams(list);
              // Initiate an API call and parse the result.
              try {
                  // IAcsClient supports two methods to obtain the response. One is to obtain the result of the original API call, that is, the HttpResponse response, by calling the doAction method. The sample code is as follows:
                  //HttpResponse httpResponse = client.doAction(describeCdnServiceRequest);
                  //System.out.println(httpResponse.getUrl());
                  //System.out.println(new String(httpResponse.getContent()));
                  // The other is to obtain the deserialized object by calling the getAcsResponse method. The sample code is as follows:
                  SaveBatchTaskForCreatingOrderActivateResponse response = client.getAcsResponse(request);
                  System.out.println(response.getTaskNo());
              } catch (ServerException e) {
                  e.printStackTrace();
              } catch (ClientException e) {
                  e.printStackTrace();
              }
          }
      }