Skip to content

Nexmo REST API client for .NET, ASP.NET, ASP.NET MVC written in C#. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.

License

Notifications You must be signed in to change notification settings

edgarjscg02/nexmo-dotnet

 
 

Repository files navigation

Nexmo Client Library for C#/.NET

You can use this C# client library to integrate Nexmo's APIs to your application. To use this, you'll need a Nexmo account. Sign up for free at nexmo.com.

Installation:

To use the client library you'll need to have created a Nexmo account.

To install the C# client library using NuGet:

  • Run the following command in the Package Manager Console:
    Install-Package Nexmo.Csharp.Client

Alternatively:

  • Download or build (see developer instructions) the Nexmo.Api.dll.
  • If you have downloaded a release, ensure you are referencing the required dependencies by either including them with your project's NuGet dependencies or manually referencing them.
  • Reference the assembly in your code.

Configuration:

  • Provide the nexmo URLs, API key, secret, and application credentials (for JWT) in appsettings.json:
{
  "appSettings": {
    "Nexmo.UserAgent": "myApp/1.0",
    "Nexmo.Url.Rest": "https://rest.nexmo.com",
    "Nexmo.Url.Api": "https://api.nexmo.com",
    "Nexmo.api_key": "<YOUR KEY>",
    "Nexmo.api_secret": "<YOUR SECRET>",
    
    "Nexmo.Application.Id": "ffffffff-ffff-ffff-ffff-ffffffffffff",
    "Nexmo.Application.Key": "c:\\path\\to\\your\\application\\private.key"
  }
}
  • In v2.1.0+, you may also continue to use web.config for configuration:
<appSettings>
  <add key="Nexmo.UserAgent" value="myApp/1.0" />
  <add key="Nexmo.Url.Rest" value="https://rest.nexmo.com" />
  <add key="Nexmo.Url.Api" value="https://api.nexmo.com" />
  <add key="Nexmo.api_key" value="<YOUR KEY>" />
  <add key="Nexmo.api_secret" value="<YOUR SECRET>" />
</appSettings>
  • In the event multiple configuration files are found, the order of precedence is as follows:

    • appsettings.json which overrides
    • settings.json which overrides
    • <executing process name>.config which overrides
    • app.config which overrides
    • web.config
  • As you are able, please move your project to JSON configuration as XML configuration will be going away in a future release.

Configuration Reference

Key Description
Nexmo.api_key Your API key from the dashboard
Nexmo.api_secret Your API secret from the dashboard
Nexmo.Application.Id Your application ID
Nexmo.Application.Key Path to your application key
Nexmo.Url.Rest Optional. Nexmo REST API base URL. Defaults to https://rest.nexmo.com
Nexmo.Url.Api Optional. Nexmo API base URL. Defaults to https://api.nexmo.com
Nexmo.Api.RequestsPerSecond Optional. Throttle to specified requests per second.
Nexmo.UserAgent Optional. Your app-specific usage identifier in the format of name/version. Example: "myApp/1.0"

Logging

From 2.2.0 onward, you can request console logging by placing a logging.json file alongside your appsettings.json configuration.

Note that logging Nexmo.Api messages will very likely expose your key and secret to the console as they can be part of the query string.

Example logging.json contents that would log all requests as well as major configuration and authentication errors:

{
  "IncludeScopes": "true",
  "LogLevel": {
    "Default": "Debug",
    "Nexmo.Api": "Debug",
    "Nexmo.Api.Authentication": "Error",
    "Nexmo.Api.Configuration": "Error"
  }
}

Examples

We are working on a separate repository for .NET examples. Check it out here!

The following examples show how to:

Sending a Message

Use Nexmo's SMS API to send a SMS message.

var results = SMS.Send(new SMS.SMSRequest
{
    from = "15555551212",
    to = "17775551212",
    text = "this is a test"
});

Receiving a Message

Use Nexmo's SMS API to receive a SMS message. Assumes your Nexmo endpoint is configured.

public ActionResult Get([FromUri]SMS.SMSDeliveryReceipt response)
{
    return new HttpStatusCodeResult(HttpStatusCode.OK);
}

NOTE: [FromUri] is deprecated in .NET Core; [FromQuery] works in this case.

Initiating a Call

Use Nexmo's Voice API to initiate a voice call.

NOTE: You must have a valid Application ID and private key in order to make voice calls. Use either Nexmo.Api.Application or Nexmo's Node.js-based CLI tool to register. See the Application API documentation for details.

using Nexmo.Api.Voice;

Call.Do(new Call.CallCommand
{
    to = new[]
    {
        new Call.Endpoint {
            type = "phone",
            number = "15555551212"
        }
    },
    from = new Call.Endpoint
    {
        type = "phone",
        number = "15557772424"
    },
    answer_url = new[]
    {
        "https://nexmo-community.github.io/ncco-examples/first_call_talk.json"
    }
});

Additional Examples

  • Check out the sample MVC application and tests for more examples. Make sure to copy appsettings.json.example/web.config.example to appsettings.json/web.config and enter your key/secret.

API Coverage

  • Account
    • Balance
    • Pricing
    • Settings
    • Top Up
    • Numbers
      • Search
      • Buy
      • Cancel
      • Update
  • Number Insight
    • Basic
    • Standard
    • Advanced
    • Webhook Notification
  • Verify
    • Verify
    • Check
    • Search
    • Control
  • Search
    • Message
    • Messages
    • Rejections
  • Messaging
    • Send
    • Delivery Receipt
    • Inbound Messages
    • Search
      • Message
      • Messages
      • Rejections
    • US Short Codes
      • Two-Factor Authentication
      • Event Based Alerts
        • Sending Alerts
        • Campaign Subscription Management
  • Application
    • Create
    • List
    • Update
    • Delete
  • Call
    • Outbound
    • Get
    • List
    • Edit
    • TTS
    • Stream
    • DTMF

Contributing

Targeted frameworks:

  • 4.5.2
  • 4.6, 4.6.1, 4.6.2
  • .NET Standard 1.6

Visual Studio 2015 is required (Community should be fine). Update 3 is recommended.

  1. Get latest code either by cloning the repository or downloading a snapshot of the source.
  2. Open "Nexmo.Api.sln"
  3. Build! NuGet dependencies should be brought down automatically; check your settings if they are not.

Pull requests are welcome!

Thanks

Special thanks to our contributors:

License

This library is released under the MIT License

About

Nexmo REST API client for .NET, ASP.NET, ASP.NET MVC written in C#. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 99.5%
  • Other 0.5%