The Domains service provides SDKs for four programming languages: Java, Python, PHP, and .NET. This topic describes how to download and use the SDKs for these languages.

Getting started

This section illustrates how to install and use the SDK for Java.
  1. Log on to the Alibaba Cloud official website. Create and manage the AccessKey pair of 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.
              // Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account because the account has permissions on all API operations. We recommend that you use a Resource Access Management (RAM) user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console.
              // In this example, the AccessKey ID and AccessKey secret are configured as environment variables. You can also save your AccessKey pair in the configuration file based on your business requirements.
              // To prevent password leaks, we recommend that you do not hard-code your AccessKey ID and AccessKey secret in your code file.
              String accessKeyId = System.getenv("DOMAIN_AK_ENV");
              String accessKeySecret = System.getenv("DOMAIN_SK_ENV");
              IClientProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
              // If the message "Can not find endpoint to access" is returned, 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("example.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 by calling the doAction method. The result of the original API call is the HttpResponse response. The following code provides an example:
                  //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 following code provides an example:
                  SaveBatchTaskForCreatingOrderActivateResponse response = client.getAcsResponse(request);
                  System.out.println(response.getTaskNo());
              } catch (ServerException e) {
                  e.printStackTrace();
              } catch (ClientException e) {
                  e.printStackTrace();
              }
          }
      }