サブアカウントの一時停止

このコード・スニペットでは、Subaccountsを一時停止する方法を説明します。

以下の変数が、便利な方法で必要な値に設定されていることを確認してください:

キー 説明
VONAGE_API_KEY 親アカウントのAPIキー。
VONAGE_API_SECRET 親アカウントのAPIシークレット。
SUBACCOUNT_KEY 停止するSubaccountのAPIキー。

コードを書く

suspend-subaccount.sh に以下を追加する:

curl -X "PATCH" "https://api.nexmo.com/accounts/$VONAGE_API_KEY/subaccounts/$SUBACCOUNT_KEY" -u $VONAGE_API_KEY:$VONAGE_API_SECRET \
     -H "Content-Type: application/json"  \
     -d $'{"suspended":true}'

全文を見る

コードを実行する

このファイルをあなたのマシンに保存し、実行する:

bash suspend-subaccount.sh

前提条件

npm install @vonage/subaccounts

suspend-subaccount.js という名前のファイルを作成し、以下のコードを追加する:

const { SubAccounts } = require('@vonage/subaccounts');

const subAccountClient = new SubAccounts({
  apiKey: VONAGE_API_KEY,
  apiSecret: VONAGE_API_SECRET,
});

全文を見る

コードを書く

suspend-subaccount.js に以下を追加する:

subAccountClient.updateSubAccount(
  SUBACCOUNT_KEY,
  { suspended: true },
)
  .then((subAccount) => console.log(subAccount))
  .catch((error) => console.error(error));

全文を見る

コードを実行する

このファイルをあなたのマシンに保存し、実行する:

node suspend-subaccount.js

前提条件

build.gradle に以下を追加する:

implementation 'com.vonage:server-sdk-kotlin:2.1.1'

SuspendSubaccount という名前のファイルを作成し、main メソッドに以下のコードを追加する:

val client = Vonage {
    apiKey(VONAGE_API_KEY)
    apiSecret(VONAGE_API_SECRET)
}

全文を見る

コードを書く

SuspendSubaccount ファイルのmain メソッドに以下を追加する:

val subaccount = client.subaccounts.subaccount(SUBACCOUNT_KEY).suspended(true)

全文を見る

コードを実行する

Gradle用のアプリケーション プラグインを使うことで、アプリケーションの実行を簡単にすることができます。build.gradle を以下のように更新する:

apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''

以下のgradle コマンドを実行し、com.vonage.quickstart.kt.subaccountsSuspendSubaccount を含むパッケージに置き換えてアプリケーションを実行する:

gradle run -Pmain=com.vonage.quickstart.kt.subaccounts.SuspendSubaccount

前提条件

build.gradle に以下を追加する:

implementation 'com.vonage:server-sdk:9.3.1'

DeactivateSubaccount という名前のファイルを作成し、main メソッドに以下のコードを追加する:

VonageClient client = VonageClient.builder()
		.apiKey(VONAGE_API_KEY)
		.apiSecret(VONAGE_API_SECRET)
		.build();

全文を見る

コードを書く

DeactivateSubaccount ファイルのmain メソッドに以下を追加する:

Account subaccount = client.getSubaccountsClient().updateSubaccount(
		UpdateSubaccountRequest.builder(SUBACCOUNT_KEY).suspended(true).build()
);

全文を見る

コードを実行する

Gradle用のアプリケーション プラグインを使うことで、アプリケーションの実行を簡単にすることができます。build.gradle を以下のように更新する:

apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''

以下のgradle コマンドを実行し、com.vonage.quickstart.subaccountsDeactivateSubaccount を含むパッケージに置き換えてアプリケーションを実行する:

gradle run -Pmain=com.vonage.quickstart.subaccounts.DeactivateSubaccount

前提条件

Install-Package Vonage

SuspendAccountRequest.cs という名前のファイルを作成し、以下のコードを追加する:

using Vonage;
using Vonage.Request;
using Vonage.SubAccounts.UpdateSubAccount;

全文を見る

SuspendAccountRequest.cs に以下を追加する:

var credentials = Credentials.FromApiKeyAndSecret(VONAGE_API_KEY, VONAGE_API_SECRET);
var client = new VonageClient(credentials);

全文を見る

コードを書く

SuspendAccountRequest.cs に以下を追加する:

var request = UpdateSubAccountRequest.Build().WithSubAccountKey(SUBACCOUNT_KEY)
    .SuspendAccount()
    .Create();
var response = await client.SubAccountsClient.UpdateSubAccountAsync(request);

全文を見る

前提条件

composer require vonage/client

suspend-subaccount.php という名前のファイルを作成し、以下のコードを追加する:

$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);

全文を見る

コードを書く

suspend-subaccount.php に以下を追加する:

$account = new \Vonage\Subaccount\SubaccountObjects\Account();
$account->setSuspended(true);

$subaccount = $client->subaccount()->updateSubaccount(VONAGE_API_KEY, SUBACCOUNT_KEY, $account);

全文を見る

コードを実行する

このファイルをあなたのマシンに保存し、実行する:

php suspend-subaccount.php

前提条件

pip install vonage python-dotenv

コードを書く

suspend-subaccount.py に以下を追加する:

from vonage import Auth, Vonage
from vonage_subaccounts import ModifySubaccountOptions, Subaccount

client = Vonage(Auth(api_key=VONAGE_API_KEY, api_secret=VONAGE_API_SECRET))

response: Subaccount = client.subaccounts.modify_subaccount(
    subaccount_api_key=SUBACCOUNT_KEY,
    options=ModifySubaccountOptions(suspended=True),
)

print(response)

全文を見る

コードを実行する

このファイルをあなたのマシンに保存し、実行する:

python subaccounts/suspend-subaccount.py

前提条件

gem install vonage

suspend-subaccount.rb という名前のファイルを作成し、以下のコードを追加する:

client = Vonage::Client.new(
  api_key: VONAGE_API_KEY,
  api_secret: VONAGE_API_SECRET
)

全文を見る

コードを書く

suspend-subaccount.rb に以下を追加する:

client.subaccounts.update(
  subaccount_key: SUBACCOUNT_KEY,
  suspended: true
)

全文を見る

コードを実行する

このファイルをあなたのマシンに保存し、実行する:

ruby suspend-subaccount.rb

試してみる

コードを実行すると、親アカウントの指定されたSubaccountsが一時停止されます。