Configure the settings for your account
You can programmatically configure the settings for your account, such as the callback URLs that the webhooks will use.
Example
This example shows how to set the URL that will be called when your Vonage number receives an SMS.
Key | Description |
---|---|
VONAGE_API_KEY |
Your Vonage API key (see it on your dashboard). |
VONAGE_API_SECRET |
Your Vonage API secret (also available on your dashboard). |
SMS_CALLBACK_URL |
The publicly-accessible URL that Vonage should send information to when your Vonage number receives an SMS |
Write the code
Add the following to configure-account.sh
:
curl -X POST "https://rest.nexmo.com/account/settings?api_key=$VONAGE_API_KEY&api_secret=$VONAGE_API_SECRET" \
-d moCallBackUrl=$SMS_CALLBACK_URL
Run your code
Save this file to your machine and run it:
bash configure-account.sh
Prerequisites
npm install @vonage/server-sdk
Create a file named configure-account.js
and add the following code:
const vonage = new Vonage({
apiKey: VONAGE_API_KEY,
apiSecret: VONAGE_API_SECRET
})
Write the code
Add the following to configure-account.js
:
vonage.account.updateSMSCallback(SMS_CALLBACK_URL, (err, result) => {
console.log(result);
});
Run your code
Save this file to your machine and run it:
node configure-account.js
Prerequisites
Add the following to `build.gradle`:
compile 'com.vonage:client:6.2.0'
Create a class named ConfigureAccount
and add the following code to the main
method:
VonageClient client = VonageClient.builder()
.apiKey(VONAGE_API_KEY)
.apiSecret(VONAGE_API_SECRET)
.build();
Write the code
Add the following to the main
method of the ConfigureAccount
class:
AccountClient accountClient = client.getAccountClient();
SettingsResponse response = accountClient.updateSmsIncomingUrl(SMS_CALLBACK_URL);
System.out.println("SMS Callback URL is now " + response.getIncomingSmsUrl());
Run your code
We can use the application
plugin for Gradle to simplify the running of our application.
Update your build.gradle
with the following:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''
Run the following gradle
command to execute your application, replacing com.vonage.quickstart.account
with the package containing ConfigureAccount
:
gradle run -Pmain=com.vonage.quickstart.account.ConfigureAccount
Prerequisites
Install-Package Vonage
Create a file named ChangeAccountSettings.cs
and add the following code:
using Vonage;
using Vonage.Request;
using Vonage.Accounts;
Add the following to ChangeAccountSettings.cs
:
var credentials = Credentials.FromApiKeyAndSecret(VONAGE_API_KEY, VONAGE_API_SECRET);
var client = new VonageClient(credentials);
Write the code
Add the following to ChangeAccountSettings.cs
:
var request = new AccountSettingsRequest() { MoCallBackUrl = SMS_CALLBACK_URL };
var response = client.AccountClient.ChangeAccountSettings(request);
Prerequisites
composer require vonage/client
Create a file named configure-account.php
and add the following code:
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);
Write the code
Add the following to configure-account.php
:
$response = $client->account()->updateConfig([
"sms_callback_url" => SMS_CALLBACK_URL
]);
print_r($response->toArray());
Run your code
Save this file to your machine and run it:
php configure-account.php
Prerequisites
pip install vonage
Create a file named configure-account.py
and add the following code:
client = vonage.Client(key=VONAGE_API_KEY, secret=VONAGE_API_SECRET)
Write the code
Add the following to configure-account.py
:
result = client.update_settings({'moCallBackUrl':SMS_CALLBACK_URL})
pprint(result)
Run your code
Save this file to your machine and run it:
python configure-account.py
Prerequisites
gem install vonage
Create a file named configure-account.rb
and add the following code:
client = Vonage::Client.new(
api_key: VONAGE_API_KEY,
api_secret: VONAGE_API_SECRET
)
Write the code
Add the following to configure-account.rb
:
result = client.account.update(
moHttpUrl: SMS_CALLBACK_URL
)
result.to_h.each do |key, value|
puts "#{key}: #{value}"
end
Run your code
Save this file to your machine and run it:
ruby configure-account.rb
The example outputs the current settings of your account, after it was updated with the new URL.