Help Center/ NAT Gateway/ API Reference/ APIs of Public NAT Gateways/ Public NAT Gateway/ Changing the Billing Mode of a Public NAT Gateway from Pay-per-Use to Yearly/Monthly
Updated on 2025-12-10 GMT+08:00

Changing the Billing Mode of a Public NAT Gateway from Pay-per-Use to Yearly/Monthly

Function

This API is used to change the billing mode of a public NAT gateway from pay-per-use to yearly/monthly.

Calling Method

For details, see Calling APIs.

URI

POST /v2/{project_id}/nat_gateways/{nat_gateway_id}/change_to_period

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Specifies the project ID.

nat_gateway_id

Yes

String

Specifies the public NAT gateway ID.

Request Parameters

Table 2 Request body parameters

Parameter

Mandatory

Type

Description

prepaid_options

No

PrepaidOptions object

Specifies the payment attributes.

Table 3 PrepaidOptions

Parameter

Mandatory

Type

Description

period_type

Yes

String

Subscription period type. There are two options:

  • month: monthly subscriptions

  • year: yearly subscriptions

period_num

Yes

Integer

Number of subscription periods. The value varies depending on the operations policy.

  • The value ranges from 1 to 9, if period_type is set to month.

  • The value ranges from 1 to 3, if period_type is set to year.

is_auto_renew

No

Boolean

Whether to enable auto renewal.

  • true: Auto renewal is enabled.

  • false: Auto renewal is disabled.

is_auto_pay

No

Boolean

Whether the payment will be automatically deducted from your account balance when an order is submitted.

  • true: The order will be automatically paid.

  • false: The order will not be automatically paid.

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

order_id

String

Specifies the order ID.

Example Requests

POST https://{NAT_endpoint}/v2/70505c941b9b4dfd82fd351932328a2f/nat_gateways/e1cacb3c-46a0-4c8e-9c4a-91eb63635f62/change_to_period

{
  "prepaid_options" : {
    "period_type" : "month",
    "period_num" : 1,
    "is_auto_renew" : false,
    "is_auto_pay" : true
  }
}

Example Responses

Status code: 200

Successful request.

{
  "order_id" : "CS2304211201WYELB"
}

SDK Sample Code

The SDK sample code is as follows.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.nat.v2.region.NatRegion;
import com.huaweicloud.sdk.nat.v2.*;
import com.huaweicloud.sdk.nat.v2.model.*;


public class UpdateNatGatewayToPeriodSolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");
        String projectId = "{project_id}";

        ICredential auth = new BasicCredentials()
                .withProjectId(projectId)
                .withAk(ak)
                .withSk(sk);

        NatClient client = NatClient.newBuilder()
                .withCredential(auth)
                .withRegion(NatRegion.valueOf("<YOUR REGION>"))
                .build();
        UpdateNatGatewayToPeriodRequest request = new UpdateNatGatewayToPeriodRequest();
        request.withNatGatewayId("{nat_gateway_id}");
        UpdateNatGatewayToPeriodRequestBody body = new UpdateNatGatewayToPeriodRequestBody();
        PrepaidOptions prepaidOptionsbody = new PrepaidOptions();
        prepaidOptionsbody.withPeriodType(PrepaidOptions.PeriodTypeEnum.fromValue("month"))
            .withPeriodNum(1)
            .withIsAutoRenew(false)
            .withIsAutoPay(true);
        body.withPrepaidOptions(prepaidOptionsbody);
        request.withBody(body);
        try {
            UpdateNatGatewayToPeriodResponse response = client.updateNatGatewayToPeriod(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdknat.v2.region.nat_region import NatRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdknat.v2 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]
    projectId = "{project_id}"

    credentials = BasicCredentials(ak, sk, projectId)

    client = NatClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(NatRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = UpdateNatGatewayToPeriodRequest()
        request.nat_gateway_id = "{nat_gateway_id}"
        prepaidOptionsbody = PrepaidOptions(
            period_type="month",
            period_num=1,
            is_auto_renew=False,
            is_auto_pay=True
        )
        request.body = UpdateNatGatewayToPeriodRequestBody(
            prepaid_options=prepaidOptionsbody
        )
        response = client.update_nat_gateway_to_period(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    nat "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/nat/v2"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/nat/v2/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/nat/v2/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")
    projectId := "{project_id}"

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithProjectId(projectId).
        Build()

    client := nat.NewNatClient(
        nat.NatClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.UpdateNatGatewayToPeriodRequest{}
	request.NatGatewayId = "{nat_gateway_id}"
	isAutoRenewPrepaidOptions:= false
	isAutoPayPrepaidOptions:= true
	prepaidOptionsbody := &model.PrepaidOptions{
		PeriodType: model.GetPrepaidOptionsPeriodTypeEnum().MONTH,
		PeriodNum: int32(1),
		IsAutoRenew: &isAutoRenewPrepaidOptions,
		IsAutoPay: &isAutoPayPrepaidOptions,
	}
	request.Body = &model.UpdateNatGatewayToPeriodRequestBody{
		PrepaidOptions: prepaidOptionsbody,
	}
	response, err := client.UpdateNatGatewayToPeriod(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.

Status Codes

Status Code

Description

200

Successful request.

Error Codes

See Error Codes.