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
NEXMO_API_KEY Your Nexmo API key.
NEXMO_API_SECRET Your Nexmo API secret.

Write the code

Add the following to create-application.sh:

Copy to Clipboard
curl -X "POST" "https://api.nexmo.com/v2/applications" \
     -H 'Content-Type: application/json' \
     -u "$NEXMO_API_KEY:$NEXMO_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"
        }
      }
    }
  }
}'

View full source

Run your code

Save this file to your machine and run it:

./create-application.sh

Prerequisites

Install dependencies

npm install nexmo@beta
Initialize your dependencies

Create a file named app.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 app.js:

Copy to Clipboard
nexmo.applications.create({
    name: 'My 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 app.js

Prerequisites

Install dependencies

pip install nexmo
Initialize your dependencies

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

Copy to Clipboard
response = client.application_v2.create_application({
    "name": "Code Example 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"
                }
            }
        }
    }
})

pprint(response)

View full source

Run your code

Save this file to your machine and run it:

python3 create-application.py