Updated on 2023-07-17 GMT+08:00

Changing the ECS Billing Mode

Function

This API is used to change the ECS billing mode.

Constraints

  • This API can only be used to change the billing mode from pay-per-use to yearly/monthly.
  • You can batch change the billing modes of a maximum of 10 ECSs.
  • The EIP bound to the ECS whose billing mode is to be changed must be exclusive and billed by bandwidth.
  • The billing modes of ECSs that have shared EVS disks, DSS disks, or DESS disks attached cannot be changed.
  • If you want to use a coupon, set auto_pay in prepaid_options to false and pay for the product by referring to Paying Yearly/Monthly Product Orders, or use the coupon to pay for the product on the console.
  • The billing modes of ECSs on Dedicated Hosts (DeHs), Dedicated Clouds (DeCs), and edge clouds cannot be changed.
  • The billing modes of spot ECSs cannot be changed.

URI

POST /v1/{project_id}/cloudservers/actions/change-charge-mode

Table 1 describes the parameters in the URI.
Table 1 Parameter description

Parameter

Mandatory

Description

project_id

Yes

Specifies the project ID.

For details about how to obtain the ID, see Obtaining a Project ID.

Request

Table 2 Request parameters

Parameter

Mandatory

Type

Description

server_ids

Yes

Array of String

Specifies the IDs of ECSs whose billing modes are to be changed from pay-per-use to yearly/monthly.

charge_mode

Yes

String

Specifies the new billing mode.

prePaid: Change the billing mode to yearly/monthly.

prepaid_options

No

Object

Specifies the yearly/monthly billing mode. This parameter is mandatory when charge_mode is set to prePaid.

For details, see Table 3.

dry_run

No

Boolean

Specifies whether to check the request and change the billing mode.

  • true: The request is sent, but the billing mode is not changed. Check items include mandatory parameters and request format.
    • If the check fails, the system returns an error.
    • If the check is successful, the system returns status code 202.
  • false: The request is sent and the billing mode will be changed after the check is passed.

The default value is false.

Table 3 prepaid_options field description

Parameter

Mandatory

Type

Description

include_data_disks

No

Boolean

Specifies whether to change the billing modes of all pay-per-use data disks to yearly/monthly.

If this parameter is true, the billing modes of non-shared pay-per-use disks are changed to yearly/monthly.

The billing modes of ECSs that have shared EVS disks, DSS disks, or DESS disks attached cannot be changed.

The default value is false.

include_publicips

No

Boolean

Specifies whether to change the billing modes of EIPs that are exclusive and billed by bandwidth to yearly/monthly.

After the EIPs are changed to yearly/monthly, they can be unbound or deleted separately.

The default value is false.

period_type

Yes

String

Specifies the subscription period.

Value options:

  • month: indicates that the subscription period is month.
  • year: indicates that the subscription period is year.

period_num

Yes

String

Specifies the number of subscription periods.

Value range:

  • When period_type is set to month, the value range is from 1 to 9.
  • When period_type is set to year, the value range is from 1 to 3.

auto_pay

No

Boolean

Specifies whether to enable automatic payment.

Value options:

  • true: Automatic payment is enabled. Ensure that the account balance is sufficient, or abnormal orders are generated and the original orders are discarded.
  • false: Orders are generated and no fees are deducted.

The default value is false.

auto_renew

No

Boolean

Specifies whether to enable auto-renewal.

Value options:

  • true: Auto-renewal is enabled.
  • false: Auto-renewal is disabled.

The default value is false.

Response

Table 4 Parameter description

Parameter

Type

Description

order_id

String

Specifies the ID of the order for changing the billing mode to yearly/monthly.

Example Request

Change the billing mode of an ECS and the exclusive EIP billed by bandwidth to yearly/monthly with the subscription period set to one month.

POST https://{endpoint}/v1/{project_id}/cloudservers/actions/change-charge-mode

{
    "server_ids": [
        "f631ee2c-1caf-4c4f-9cee-f3181b8e44ad"
    ],
    "charge_mode": "prePaid",
    "prepaid_options": {
        "include_publicips": true,
        "include_data_disks": false,
        "period_type": "month",
        "period_num": "1",
        "auto_pay": false,
        "auto_renew": false
    },
    "dry_run": false
}

Example Response

{
    order_id: "CS2102041657OL0EY"
}

Error Codes

See Error Codes.