Join us in San Francisco on the 29/30th of October for two days of developer workshops and technical talks

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 Nexmo number receives an SMS.

Key Description
SMS_CALLBACK_URL The publicly-accessible URL that Nexmo should send information to when your Nexmo number receives an SMS

Write the code

Add the following to configure-account.sh:

Copy to Clipboard
curl -X POST "https://rest.nexmo.com/account/settings?api_key=$NEXMO_API_KEY&api_secret=$NEXMO_API_SECRET" \
    -d moCallBackUrl=$SMS_CALLBACK_URL

View full source

Run your code

Save this file to your machine and run it:

bash configure-account.sh

Prerequisites

Install dependencies

npm install nexmo
Initialize your dependencies

Create a file named configure-account.js and add the following code:

Copy to Clipboard
const nexmo = new Nexmo({
  apiKey: NEXMO_API_KEY,
  apiSecret: NEXMO_API_SECRET
})

View full source

Write the code

Add the following to configure-account.js:

Copy to Clipboard
nexmo.account.updateSMSCallback(SMS_CALLBACK_URL, (err, result) => {
    console.log(result);
});

View full source

Run your code

Save this file to your machine and run it:

node configure-account.js

Prerequisites

Install dependencies

Add the following to build.gradle:

compile 'com.nexmo:client:5.1.0'
Initialize your dependencies

Create a class named ConfigureAccount and add the following code to the main method:

Copy to Clipboard
NexmoClient client = NexmoClient.builder()
        .apiKey(NEXMO_API_KEY)
        .apiSecret(NEXMO_API_SECRET)
        .build();

View full source

Write the code

Add the following to the main method of the ConfigureAccount class:

Copy to Clipboard
AccountClient accountClient = client.getAccountClient();

SettingsResponse response = accountClient.updateSmsIncomingUrl(SMS_CALLBACK_URL);
System.out.println("SMS Callback URL is now " + response.getIncomingSmsUrl());

View full source

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.nexmo.quickstart.account with the package containing ConfigureAccount:

gradle run -Pmain=com.nexmo.quickstart.account.ConfigureAccount

Prerequisites

Install dependencies

Install-Package Nexmo.Csharp.Client
Initialize your dependencies

Create a file named AccountController.cs and add the following code:

Copy to Clipboard
var client = new Client(creds: new Nexmo.Api.Request.Credentials
{
    ApiKey = "NEXMO_API_KEY",
    ApiSecret = "NEXMO_API_SECRET"
});

View full source

Write the code

Add the following to AccountController.cs:

Copy to Clipboard
var result = Client.Account.SetSettings(null, SMS_CALLBACK_URL, null );

if (result != null)
{
    ViewBag.result = $"Your SMS callback url has been updated to {result.moCallbackUrl}";
}

View full source

Prerequisites

Install dependencies

composer require nexmo/client
Initialize your dependencies

Create a file named configure-account.php and add the following code:

Copy to Clipboard
$basic  = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client($basic);

View full source

Write the code

Add the following to configure-account.php:

Copy to Clipboard
$response = $client->account()->updateConfig([
    "sms_callback_url" => SMS_CALLBACK_URL
]);
print_r($response->data);

View full source

Run your code

Save this file to your machine and run it:

php configure-account.php

Prerequisites

Install dependencies

pip install nexmo
Initialize your dependencies

Create a file named configure-account.py and add the following code:

Copy to Clipboard
client = nexmo.Client(key=NEXMO_API_KEY, secret=NEXMO_API_SECRET)

View full source

Write the code

Add the following to configure-account.py:

Copy to Clipboard
result = client.update_settings({'moCallBackUrl':SMS_CALLBACK_URL})
pprint(result)

View full source

Run your code

Save this file to your machine and run it:

python configure-account.py

Prerequisites

Install dependencies

gem install nexmo
Initialize your dependencies

Create a file named configure-account.rb and add the following code:

Copy to Clipboard
client = Nexmo::Client.new(
  api_key: NEXMO_API_KEY,
  api_secret: NEXMO_API_SECRET
)

View full source

Write the code

Add the following to configure-account.rb:

Copy to Clipboard
result = client.account.update(
  moHttpUrl: SMS_CALLBACK_URL
)

result.to_h.each do |key, value|
  puts "#{key}: #{value}"
end

View full source

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.