Create an Application
In this code snippet you will see how to create 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 |
|---|---|
VONAGE_API_KEY | Your Vonage API key (see it on your dashboard). |
VONAGE_API_SECRET | Your Vonage API secret (also available on your dashboard). |
Write the code
Add the following to create-application.sh:
curl -X "POST" "https://api.nexmo.com/v2/applications" \
-H 'Content-Type: application/json' \
-u "$VONAGE_API_KEY:$VONAGE_API_SECRET" \
-d $'{
"name": "Code Snippets V2 Application",
"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": "GET"
},
"fallback_answer_url": {
"address": "https://fallback.example.com/webhooks/answer",
"http_method": "GET"
},
"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": {},
"verify": {
"webhooks": {Run your code
Save this file to your machine and run it:
Prerequisites
npm install @vonage/server-sdkCreate a file named create-application.js and add the following code:
Run your code
Save this file to your machine and run it:
Prerequisites
Add the following to build.gradle:
implementation 'com.vonage:server-sdk-kotlin:2.1.1'Create a file named CreateApplication and add the following code to the main method:
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.kt.application with the package containing CreateApplication:
Prerequisites
Add the following to build.gradle:
implementation 'com.vonage:server-sdk:9.3.1'Create a file named CreateApplication 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 CreateApplication file:
Application application = client.getApplicationClient().createApplication(
Application.builder()
.name(APPLICATION_NAME)
.addCapability(Messages.builder()
.inbound(Webhook.builder()
.address("https://example.com/webhooks/inbound")
.method(HttpMethod.POST)
.build()
)
.status(Webhook.builder()
.address("https://example.com/webhooks/status")
.method(HttpMethod.POST)
.build()
)
.build()
)
.build()
);
System.out.println("Application Created:");
System.out.println(application.toJson());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.application with the package containing CreateApplication:
Prerequisites
Install-Package VonageCreate a file named CreateApplication.cs and add the following code:
Add the following to CreateApplication.cs:
Prerequisites
composer require vonage/clientCreate a file named create-application.php and add the following code:
Run your code
Save this file to your machine and run it:
Prerequisites
pip install vonage python-dotenvRun your code
Save this file to your machine and run it:
Prerequisites
gem install vonageCreate a file named create-application.rb and add the following code:
Run your code
Save this file to your machine and run it: