Update Application

In this code snippet you will see how to update an Application.

Example

You will need to ensure that the following replaceable values are set in the example code using any convenient method:

Key Description
NEXMO_API_KEY Your Nexmo API key.
NEXMO_API_SECRET Your Nexmo API secret.
NEXMO_APPLICATION_ID The application ID for the Nexmo application you want to update.

Write the code

Add the following to update-application.sh:

Copy to Clipboard
curl -X "PUT" "https://api.nexmo.com/v2/applications/$NEXMO_APPLICATION_ID" \
     -H 'Content-Type: application/json' \
     -u "$NEXMO_API_KEY:$NEXMO_API_SECRET" \
     -d $'{
  "name": "New App Name",
  "capabilities": {
    "messages": {
      "webhooks": {
        "inbound_url": {
          "address": "https://example.com/webhooks/inbound",
          "http_method": "POST"
        },
        "status_url": {
          "address": "https://example.com/webhooks/status",
          "http_method": "POST"
        }
      }
    },
    "voice": {
      "webhooks": {
        "answer_url": {
          "address": "https://example.com/webhooks/answer",
          "http_method": "POST"
        },
        "event_url": {
          "address": "https://example.com/webhooks/event",
          "http_method": "POST"
        }
      }
    },
    "rtc": {
      "webhooks": {
        "event_url": {
          "address": "https://example.com/webhooks/event",
          "http_method": "POST"
        }
      }
    },
    "vbc": {}
  }
}'

View full source

Run your code

Save this file to your machine and run it:

./update-application.sh

Prerequisites

Install dependencies

npm install nexmo
Initialize your dependencies

Create a file named update-application.js and add the following code:

Copy to Clipboard
const Nexmo = require('nexmo')

var nexmo = new Nexmo({
    apiKey: NEXMO_API_KEY,
    apiSecret: NEXMO_API_SECRET
}, {
    debug: true
});

View full source

Write the code

Add the following to update-application.js:

Copy to Clipboard
nexmo.applications.update(NEXMO_APPLICATION_ID, {
    name: 'My updated nexmo-node Example V2 App',
    capabilities: {
      voice: {
        webhooks: {
          answer_url: {
            address: "https://example.com/webhooks/answer",
            http_method: "GET"
          },
          event_url: {
            address: "https://example.com/webhooks/event",
            http_method: "POST"
          }
        }
      },
      messages: {
        webhooks: {
          inbound_url: {
            address: "https://example.com/webhooks/inbound",
            http_method: "POST"
          },
          status_url: {
            address: "https://example.com/webhooks/status",
            http_method: "POST"
          }
        }
      },
      rtc: {
        webhooks: {
          event_url: {
            address: "https://example.com/webhooks/rtcevent",
            http_method: "POST"
          }
        }
      }
    }
}, (error, result) => {
  if(error) {
    console.error(error);
  }
  else {
    console.log(result);
  }
});

View full source

Run your code

Save this file to your machine and run it:

node update-application.js

Prerequisites

Install dependencies

Add the following to build.gradle:

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

Create a class named UpdateApplication 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 UpdateApplication class:

Copy to Clipboard
ApplicationClient applicationClient = client.getApplicationClient();
Application existingApplication = applicationClient.getApplication(NEXMO_APPLICATION_ID);

Capability messages = Messages.builder()
        .addWebhook(Webhook.Type.INBOUND,
                new Webhook("https://example.com/webhooks/inbound", HttpMethod.POST))
        .addWebhook(Webhook.Type.STATUS,
                new Webhook("https://example.com/webhooks/status", HttpMethod.POST))
        .build();

Capability voice = Voice.builder()
        .addWebhook(Webhook.Type.ANSWER,
                new Webhook("https://example.com/webhooks/answer", HttpMethod.POST))
        .addWebhook(Webhook.Type.EVENT,
                new Webhook("https://example.com/webhooks/event", HttpMethod.POST))
        .build();

Capability rtc = Rtc.builder()
        .addWebhook(Webhook.Type.EVENT,
                new Webhook("https://example.com/webhooks/event", HttpMethod.POST))
        .build();

Capability vbc = Vbc.builder().build();

Application application = applicationClient.updateApplication(
        Application.builder(existingApplication)
                .name("New Application Name")
                .addCapability(messages)
                .addCapability(voice)
                .addCapability(rtc)
                .addCapability(vbc)
                .build()
);

System.out.println("Application Updated:");
System.out.println("Old: " + existingApplication.toJson());
System.out.println("New: " + application.toJson());

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.application with the package containing UpdateApplication:

gradle run -Pmain=com.nexmo.quickstart.application.UpdateApplication

Prerequisites

Install dependencies

Install-Package Nexmo.Csharp.Client
Initialize your dependencies

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

Copy to Clipboard
const string API_KEY = "NEXMO_API_KEY";
const string API_SECRET = "NEXMO_API_SECRET";

var client = new Client(creds: new Nexmo.Api.Request.Credentials(
    nexmoApiKey: API_KEY, nexmoApiSecret: API_SECRET));

View full source

Write the code

Add the following to ApplicationSender.cs:

Copy to Clipboard
var request = new AppRequest()
{
    Id = NEXMO_APPLICATION_ID,
    Name = name,
    Capabilities = new Capabilities()
    {
        Messages = new MessagesWebhook(
            new Webhook() { Address = "https://example.com/webhooks/inbound", HttpMethod = "POST" },
            new Webhook() { Address = "https://example.com/webhooks/status", HttpMethod = "POST" }),
        Rtc = new RtcWebhook(
            new Webhook(){Address = "https://example.com/webhooks/event", HttpMethod = "POST"}),
        Voice = new VoiceWebhook(
            new Webhook() { Address = "https://example.com/webhooks/answer", HttpMethod = "GET" },
            new Webhook() { Address = "https://example.com/webhooks/event", HttpMethod = "POST" }),
        Vbc = new VbcWebhook()
    }
};

var response = client.ApplicationV2.Update(request: request);

View full source

Prerequisites

Install dependencies

composer require nexmo/client
Initialize your dependencies

Create a file named update-application.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(new \Nexmo\Client\Credentials\Container($basic));

View full source

Write the code

Add the following to update-application.php:

Copy to Clipboard
try {
    $application = $client->applications()->update([
            'name' => 'Sample PHP V2 Application',
            'capabilities' => [
                'voice' => [
                    'webhooks' => [
                        'answer_url' => [
                            'address' => "https://example.com/webhooks/answer",
                            'http_method' => "GET"
                        ],
                        'event_url' => [
                            'address' => "https://example.com/webhooks/event",
                            'http_method' => "POST"
                        ]
                    ]
                ],
                'messages' => [
                    'webhooks' => [
                        'inbound_url' => [
                            'address' => "https://example.com/webhooks/inbound",
                            'http_method' => "POST"
                        ],
                        'status_url' => [
                            'address' => "https://example.com/webhooks/status",
                            'http_method' => "POST"
                        ]
                    ]
                ],
                'rtc' => [
                    'webhooks' => [
                        'event_url' => [
                            'address' => "https://example.com/webhooks/rtcevent",
                            'http_method' => "POST"
                        ]
                    ]
                ]
            ]
        ],
        MESSAGES_APPLICATION_ID
    );

    echo $application->getId() . PHP_EOL;
    echo $application->getName() . PHP_EOL;
} catch (\InvalidArgumentException $e) {
    echo $e->getMessage() . PHP_EOL;
}

View full source

Run your code

Save this file to your machine and run it:

php update-application.php

Prerequisites

Install dependencies

pip install nexmo
Initialize your dependencies

Create a file named update-application.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 update-application.py:

Copy to Clipboard
response = client.application_v2.update_application(NEXMO_APPLICATION_ID, {
  "name": "Python Update App",
  "capabilities": {
    "messages": {
      "webhooks": {
        "inbound_url": {
          "address": "https://example.com/webhooks/inbound",
          "http_method": "POST"
        },
        "status_url": {
          "address": "https://example.com/webhooks/status",
          "http_method": "POST"
        }
      }
    },
    "voice": {
      "webhooks": {
        "answer_url": {
          "address": "https://example.com/webhooks/answer",
          "http_method": "POST"
        },
        "event_url": {
          "address": "https://example.com/webhooks/event",
          "http_method": "POST"
        }
      }
    },
    "rtc": {
      "webhooks": {
        "event_url": {
          "address": "https://example.com/webhooks/event",
          "http_method": "POST"
        }
      }
    },
    "vbc": {}
  }
})

pprint(response)

View full source

Run your code

Save this file to your machine and run it:

python3 update-application.py

Prerequisites

Install dependencies

gem install nexmo
Initialize your dependencies

Create a file named update-application.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 update-application.rb:

Copy to Clipboard
begin
  response = client.applications_v2.update(
    NEXMO_APPLICATION_ID,
    id: NEXMO_APPLICATION_ID,
    name: 'Ruby Update App',
    capabilities: {
      'messages': {
        'webhooks': {
          'inbound_url': {
            'address': 'https://example.com/webhooks/inbound',
            'http_method': 'POST'
          },
          'status_url': {
            'address': 'https://example.com/webhooks/status',
            'http_method': 'POST'
          }
        }
      },
      'voice': {
        'webhooks': {
          'answer_url': {
            'address': 'https://example.com/webhooks/answer',
            'http_method': 'POST'
          },
          'event_url': {
            'address': 'https://example.com/webhooks/event',
            'http_method': 'POST'
          }
        }
      }
    }
  )
  puts 'Application Updated Successfully' if response.id
rescue StandardError => e
  puts e.message
end

View full source

Run your code

Save this file to your machine and run it:

ruby update-application.rb