Get Started

The Twilio C# Helper Library

The twilio-csharp helper library lets you write C# code to make HTTP requests to the Twilio API.

This library is open source, so if you find a feature missing or a bug, we encourage you to contribute back to the twilio-csharp project hosted on Github.

More Documentation

The Rest API Documentation has examples written in C# for every kind of action you could take with the Twilio API. You should start there if you know what you want to do with the C# library.

If you'd like to learn more about how Twilio works, or for inspiration about what to build, try the .NET quickstarts.

You may also want to refer to the open source twilio-csharp specific documentation for more details about the functions and classes contained in the module.

Installation

Adding Twilio .NET Libraries to your .NET project

The best and easiest way to add the Twilio libraries to your .NET project is to use the NuGet package manager. NuGet is a Visual Studio extension that makes it easy to install and update third-party libraries and tools in Visual Studio.

NuGet is available for Visual Studio 2010 and Visual Studio 2012, and you can find instructions for installing the NuGet extension on the NuGet.org website.

Once you have installed the NuGet extension, you can choose to install the Twilio libraries using either the Package Manager dialog, or using the Package Manager console.

Installing via the Package Manager Dialog

To install a Twilio library using the Package Manager dialog, first open the dialog by right-clicking the References folder in your project and selecting the package manager option:

"Manage NuGet Packages" context menu

When the package manager dialog opens simply search the online catalog for ‘Twilio’. The screen shot below shows the results returned from the NuGet catalog:

Package Manager Dialog

Simply click the Install button next to the Twilio package you want to add to your project and watch as NuGet downloads the Twilio library package (and its dependencies) and adds the proper references to your project.

Twilio References

Installing via the Package Manager Console

To install a Twilio library using the Package Manager console, first open the console, then Use the Install-Package command to install the different Twilio packages:

Install REST API wrapper:

    Install-Package Twilio

Install ASP.NET MVC helpers and REST API wrapper:

    Install-Package Twilio.Mvc

Installing in WebMatrix

If you are using Microsoft’s free web developer tool WebMatrix, it also includes integration with NuGet. To add the Twilio helpers to a site created using WebMatrix simply open the WebMatrix administration website (as described here). Change the Show dropdown from Installed to Online and use the search field to Search for ‘Twilio’.

WebMatrix Package Manager

Testing your installation

Try sending yourself an SMS message, like this:

Example.cs

using System;
using Twilio;
class Example
{
  static void Main(string[] args)
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "AC32a3c49700934481addd5ce1659f04d2";
    string AuthToken = "";

    var twilio = new TwilioRestClient(AccountSid, AuthToken);
    var message = twilio.SendMessage("+14158141829", "+14159352345", "Jenny please?! I love you <3", "");

    Console.WriteLine(message.Sid);
  }
}

Using the Library

Try the .NET quickstarts and refer to the open source twilio-csharp specific documentation for details about the functions and classes contained in the library.

Exceptions

If the Twilio API returns a 400 or a 500 level HTTP response, objects returned by the twilio-csharp library will contain a non-null RestException object with information about the exception. 400-level errors are normal during API operation ("Invalid number", "Cannot deliver SMS to that number", for example) and should be checked and handled appropriately.

using Twilio;
class Example
{
  static void Main(string[] args)
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "AC32a3c49700934481addd5ce1659f04d2";
    string AuthToken = "";

    var twilio = new TwilioRestClient(AccountSid, AuthToken);
    var message = twilio.SendMessage("+14158141829", "+14159352345", "Hello World");

    if (message.RestException != null) {
        var error = message.RestException.Message;
        // handle the error ...
    }
  }
}

Getting help

Still running into problems?