purchase instances using API operations

Updated at:

You can create Global Traffic Manager (GTM) instances by calling API operations.

Prerequisites

Instance creation and renewal use the Alibaba Cloud Transaction and Billing Management API. Follow the specifications of this API when making calls.

Instance Creation Service

For more information, see Instance Creation Service.

SDK

Maven dependency:

<dependencies>
  <dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>bssopenapi20171214</artifactId>
    <version>4.1.0</version>
  </dependency>
</dependencies>

For other languages, see SDK List.

Client initialization: Install the latest Java SDK.

Important

For Alibaba Cloud China Website, use `cn-hangzhou` as the RegionId. For Alibaba Cloud International Website, use `ap-southeast-1` as the RegionId.

Create Global Traffic Manager Instances

Create Global Traffic Manager instances by calling the CreateInstance operation.

API operation name: CreateInstance

API reference: Instance Creation Service.

Parameter descriptions

Name

Type

Required

Description

Details

ProductCode

String

Yes

Product code

The product code. Set the value to dns.

ProductType

String

Yes

Product type

The product code. Set the value to:

  • dns_gtm_public_cn: For users on Alibaba Cloud China Website.

  • dns_gtm_public_intl: For users on Alibaba Cloud International Website.

SubscriptionType

String

Yes

Payment type

The payment type. Set the value to:

  • Subscription: The only billing method currently supported.

Period

Integer

Yes

Subscription period

Required when you create a subscription instance. Unit: month. For annual subscription products, enter a multiple of 12. For example:

  • 1: The purchase period is 1 month.

  • 6: The purchase period is 6 months.

  • 12: The purchase period is 1 year.

  • 36: The purchase period is 3 years.

RenewalStatus

String

No

Auto-renewal status

  • AutoRenewal: Auto-renewal.

  • ManualRenewal: Manual renewal (default value).

RenewPeriod

Integer

No

Auto-renewal period. Unit: month.

Required when you set RenewalStatus to AutoRenewal. For example:

  • 1: The auto-renewal period is 1 month.

  • 6: The auto-renewal period is 6 months.

  • 12: The auto-renewal period is 1 year.

Parameter.1.Value

String

Yes

The value of the purchased package edition

  • standard: Standard Edition

  • ultimate: Ultimate Edition

Parameter.1.Code

String

Yes

Package edition

PackageEdition

Parameter.2.Value

String

Yes

Quantity of additional detection task packages ordered

Each instance edition includes 100 health check tasks by default. Each additional health check task package contains 100 tasks. For example:

  • 0: Default value.

  • 100: Purchase 100 additional health check tasks, for a total of 200 (including the 100 default tasks).

Note

Minimum value: 0. Step size: 100. Maximum value: 100000.

Parameter.2.Code

String

Yes

Probe Task Package

HealthcheckTaskCount

Parameter.3.Value

String

Yes

The number of domestic SMS notification packages purchased

By default, each instance includes 1,000 SMS messages and typically requires no additional purchase. Each package contains 1,000 SMS messages. For example:

  • 0: Default value.

  • 1000: Purchase 1,000 additional SMS messages, for a total of 2,000 (including the 1,000 default messages).

Note

Minimum value: 0. Step size: 1000. Maximum value: 100000.

Parameter.3.Code

String

Yes

Domestic SMS notification package

SmsNotificationCount

Parameter.4.Value

String

Yes

The value of the purchased package edition

Both legacy and new instance editions are available. We recommend Global Traffic Manager 3.0 for its expanded feature set. Set the value to:

  • subscription: Old instance edition

  • subscription3.0: Global Traffic Manager 3.0 instance

Parameter.4.Code

String

Yes

Instance version

PaymentMode

Code samples

// This file is auto-generated, don't edit it. Thanks.
package com.aliyun.sample;

import com.aliyun.tea.*;

public class Sample {

    /**
     * Description :
     * <p>Initialize the client with an AccessKey pair.</p>
     * @return Client
     * 
     * @throws Exception
     */
    public static com.aliyun.bssopenapi20171214.Client createClient() throws Exception {
        // If the project code is leaked, your AccessKey pair may be leaked, which compromises the security of all resources in your account. The following code example is for reference only.
        // We recommend that you use a more secure Security Token Service (STS) method. For more information about authentication and access methods, see: https://help.aliyun.com/document_detail/378657.html.
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // Required. Ensure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured in the code runtime environment.
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Required. Ensure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured in the code runtime environment.
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        // Endpoint please refer to https://api.aliyun.com/product/BssOpenApi
        config.endpoint = "business.aliyuncs.com";
        return new com.aliyun.bssopenapi20171214.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.bssopenapi20171214.Client client = Sample.createClient();
        com.aliyun.bssopenapi20171214.models.CreateInstanceRequest.CreateInstanceRequestParameter parameter0 = new com.aliyun.bssopenapi20171214.models.CreateInstanceRequest.CreateInstanceRequestParameter()
                .setValue("standard")
                .setCode("PackageEdition");
        com.aliyun.bssopenapi20171214.models.CreateInstanceRequest.CreateInstanceRequestParameter parameter1 = new com.aliyun.bssopenapi20171214.models.CreateInstanceRequest.CreateInstanceRequestParameter()
                .setValue("100")
                .setCode("HealthcheckTaskCount");
        com.aliyun.bssopenapi20171214.models.CreateInstanceRequest.CreateInstanceRequestParameter parameter2 = new com.aliyun.bssopenapi20171214.models.CreateInstanceRequest.CreateInstanceRequestParameter()
                .setValue("1000")
                .setCode("SmsNotificationCount");
        com.aliyun.bssopenapi20171214.models.CreateInstanceRequest.CreateInstanceRequestParameter parameter3 = new com.aliyun.bssopenapi20171214.models.CreateInstanceRequest.CreateInstanceRequestParameter()
                .setValue("subscription3.0")
                .setCode("PaymentMode");
        com.aliyun.bssopenapi20171214.models.CreateInstanceRequest createInstanceRequest = new com.aliyun.bssopenapi20171214.models.CreateInstanceRequest()
                .setProductCode("dns")
                .setProductType("dns_gtm_public_cn")
                .setSubscriptionType("Subscription")
                .setPeriod(12)
                .setRenewalStatus("AutoRenewal")
                .setParameter(java.util.Arrays.asList(
                    parameter0,
                    parameter1,
                    parameter2,
                    parameter3
                ))
                .setRenewPeriod(12);
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // Run the code and print the API return value.
            client.createInstanceWithOptions(createInstanceRequest, runtime);
        } catch (TeaException error) {
            // This code is for demonstration purposes only. Handle exceptions with caution. Do not ignore exceptions in your project.
            // Error message
            System.out.println(error.getMessage());
            // Diagnostic address
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // This code is for demonstration purposes only. Handle exceptions with caution. Do not ignore exceptions in your project.
            // Error message
            System.out.println(error.getMessage());
            // Diagnostic address
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }        
    }
}
# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import os
import sys

from typing import List

from alibabacloud_bssopenapi20171214.client import Client as BssOpenApi20171214Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_bssopenapi20171214 import models as bss_open_api_20171214_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient


class Sample:
    def __init__(self):
        pass

    @staticmethod
    def create_client() -> BssOpenApi20171214Client:
        """
        Initialize the client with an AccessKey pair.
        @return: Client
        @throws Exception
        """
        # If the project code is leaked, your AccessKey pair may be leaked, which compromises the security of all resources in your account. The following code example is for reference only.
        # We recommend that you use a more secure Security Token Service (STS) method. For more information about authentication and access methods, see: https://help.aliyun.com/document_detail/378659.html.
        config = open_api_models.Config(
            # Required. Ensure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured in the code runtime environment.,
            access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
            # Required. Ensure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured in the code runtime environment.,
            access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
        )
        # Endpoint please refer to https://api.aliyun.com/product/BssOpenApi
        config.endpoint = f'business.aliyuncs.com'
        return BssOpenApi20171214Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        parameter_0 = bss_open_api_20171214_models.CreateInstanceRequestParameter(
            value='standard',
            code='PackageEdition'
        )
        parameter_1 = bss_open_api_20171214_models.CreateInstanceRequestParameter(
            value='100',
            code='HealthcheckTaskCount'
        )
        parameter_2 = bss_open_api_20171214_models.CreateInstanceRequestParameter(
            value='1000',
            code='SmsNotificationCount'
        )
        parameter_3 = bss_open_api_20171214_models.CreateInstanceRequestParameter(
            value='subscription3.0',
            code='PaymentMode'
        )
        create_instance_request = bss_open_api_20171214_models.CreateInstanceRequest(
            product_code='dns',
            product_type='dns_gtm_public_cn',
            subscription_type='Subscription',
            period=12,
            renewal_status='AutoRenewal',
            parameter=[
                parameter_0,
                parameter_1,
                parameter_2,
                parameter_3
            ],
            renew_period=12
        )
        runtime = util_models.RuntimeOptions()
        try:
            # Run the code and print the API return value.
            client.create_instance_with_options(create_instance_request, runtime)
        except Exception as error:
            # This code is for demonstration purposes only. Handle exceptions with caution. Do not ignore exceptions in your project.
            # Error message
            print(error.message)
            # Diagnostic address
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)

    @staticmethod
    async def main_async(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        parameter_0 = bss_open_api_20171214_models.CreateInstanceRequestParameter(
            value='standard',
            code='PackageEdition'
        )
        parameter_1 = bss_open_api_20171214_models.CreateInstanceRequestParameter(
            value='100',
            code='HealthcheckTaskCount'
        )
        parameter_2 = bss_open_api_20171214_models.CreateInstanceRequestParameter(
            value='1000',
            code='SmsNotificationCount'
        )
        parameter_3 = bss_open_api_20171214_models.CreateInstanceRequestParameter(
            value='subscription3.0',
            code='PaymentMode'
        )
        create_instance_request = bss_open_api_20171214_models.CreateInstanceRequest(
            product_code='dns',
            product_type='dns_gtm_public_cn',
            subscription_type='Subscription',
            period=12,
            renewal_status='AutoRenewal',
            parameter=[
                parameter_0,
                parameter_1,
                parameter_2,
                parameter_3
            ],
            renew_period=12
        )
        runtime = util_models.RuntimeOptions()
        try:
            # Run the code and print the API return value.
            await client.create_instance_with_options_async(create_instance_request, runtime)
        except Exception as error:
            # This code is for demonstration purposes only. Handle exceptions with caution. Do not ignore exceptions in your project.
            # Error message
            print(error.message)
            # Diagnostic address
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)


if __name__ == '__main__':
    Sample.main(sys.argv[1:])
// This file is auto-generated, don't edit it. Thanks.
package main

import (
  "encoding/json"
  "strings"
  "fmt"
  "os"
  bssopenapi20171214  "github.com/alibabacloud-go/bssopenapi-20171214/v5/client"
  openapi  "github.com/alibabacloud-go/darabonba-openapi/v2/client"
  util  "github.com/alibabacloud-go/tea-utils/v2/service"
  "github.com/alibabacloud-go/tea/tea"
)


// Description:
// 
// Initialize the client with an AccessKey pair.
// 
// @return Client
// 
// @throws Exception
func CreateClient () (_result *bssopenapi20171214.Client, _err error) {
  // If the project code is leaked, your AccessKey pair may be leaked, which compromises the security of all resources in your account. The following code example is for reference only.
  // We recommend that you use a more secure Security Token Service (STS) method. For more information about authentication and access methods, see: https://help.aliyun.com/document_detail/378661.html.
  config := &openapi.Config{
    // Required. Ensure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured in the code runtime environment.
    AccessKeyId: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")),
    // Required. Ensure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured in the code runtime environment.
    AccessKeySecret: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")),
  }
  // Endpoint please refer to https://api.aliyun.com/product/BssOpenApi
  config.Endpoint = tea.String("business.aliyuncs.com")
  _result = &bssopenapi20171214.Client{}
  _result, _err = bssopenapi20171214.NewClient(config)
  return _result, _err
}

func _main (args []*string) (_err error) {
  client, _err := CreateClient()
  if _err != nil {
    return _err
  }

  parameter0 := &bssopenapi20171214.CreateInstanceRequestParameter{
    Value: tea.String("standard"),
    Code: tea.String("PackageEdition"),
  }
  parameter1 := &bssopenapi20171214.CreateInstanceRequestParameter{
    Value: tea.String("100"),
    Code: tea.String("HealthcheckTaskCount"),
  }
  parameter2 := &bssopenapi20171214.CreateInstanceRequestParameter{
    Value: tea.String("1000"),
    Code: tea.String("SmsNotificationCount"),
  }
  parameter3 := &bssopenapi20171214.CreateInstanceRequestParameter{
    Value: tea.String("subscription3.0"),
    Code: tea.String("PaymentMode"),
  }
  createInstanceRequest := &bssopenapi20171214.CreateInstanceRequest{
    ProductCode: tea.String("dns"),
    ProductType: tea.String("dns_gtm_public_cn"),
    SubscriptionType: tea.String("Subscription"),
    Period: tea.Int32(12),
    RenewalStatus: tea.String("AutoRenewal"),
    Parameter: []*bssopenapi20171214.CreateInstanceRequestParameter{parameter0, parameter1, parameter2, parameter3},
    RenewPeriod: tea.Int32(12),
  }
  runtime := &util.RuntimeOptions{}
  tryErr := func()(_e error) {
    defer func() {
      if r := tea.Recover(recover()); r != nil {
        _e = r
      }
    }()
    // Run the code and print the API return value.
    _, _err = client.CreateInstanceWithOptions(createInstanceRequest, runtime)
    if _err != nil {
      return _err
    }

    return nil
  }()

  if tryErr != nil {
    var error = &tea.SDKError{}
    if _t, ok := tryErr.(*tea.SDKError); ok {
      error = _t
    } else {
      error.Message = tea.String(tryErr.Error())
    }
    // This code is for demonstration purposes only. Handle exceptions with caution. Do not ignore exceptions in your project.
    // Error message
    fmt.Println(tea.StringValue(error.Message))
    // Diagnostic address
    var data interface{}
    d := json.NewDecoder(strings.NewReader(tea.StringValue(error.Data)))
    d.Decode(&data)
    if m, ok := data.(map[string]interface{}); ok {
      recommend, _ := m["Recommend"]
      fmt.Println(recommend)
    }
    _, _err = util.AssertAsString(error.Message)
    if _err != nil {
      return _err
    }
  }
  return _err
}


func main() {
  err := _main(tea.StringSlice(os.Args[1:]))
  if err != nil {
    panic(err)
  }
}