トランスファー・バランス

このコード・スニペットでは、親アカウントの残高の一部(または全部)を Subaccounts に移す方法を説明します。

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

キー 説明
VONAGE_API_KEY 親アカウントのAPIキー。
VONAGE_API_SECRET 親アカウントのAPIシークレット。
SUBACCOUNT_KEY 指定された金額を受け取るSubaccountsのAPIキー。
AMOUNT 指定したSubaccountに移される残高の金額。

Write the code

Add the following to transfer-balance.sh:

curl -X "POST" "https://api.nexmo.com/accounts/$VONAGE_API_KEY/balance-transfers" -u $VONAGE_API_KEY:$VONAGE_API_SECRET \
     -H "Content-Type: application/json"  \
     -d $'{"from":"'$VONAGE_API_KEY'", "to":"'$SUBACCOUNT_KEY'", "amount": '$AMOUNT'}'

View full source

Run your code

Save this file to your machine and run it:

bash transfer-balance.sh

試してみる

このコードを実行すると、親 Account の残高の指定された金額が、指定された Subaccounts に転送されます。