Bandwidth C# SDK uses Nuget for Package Management
Run
nuget install Bandwidth.Iris
Or install Bandwidth.Iris via UI in Visual Studio
- Install Bandwidth.Iris
- Get an account ID, user name and password from Bandwidth for your account
- Configure the Client
var client = Client.GetInstance("accountId", "username", "password", "apiEndpoint")
//Or
//Uses the System Environment Variables as detailed below
var client = Client.GetInstance()
Environment Variable | Definition |
---|---|
BANDWIDTH_API_ACCOUNT_ID | Your Bandwidth Account Id |
BANDWIDTH_API_USERNAME | Your Bandwidth username |
BANDWIDTH_API_PASSWORD | Your Bandwidth password |
BANDWIDTH_API_ENDPOINT | https://dashboard.bandwidth.com/api |
BANDWIDTH_API_VERSION | v1.0 |
All static functions support 2 ways to be called: With a client instance as the first arg or without the client instance (default client instance will then be used)
var site = await Site.get(client, "siteId");
//Or
var site = await Site.get("siteId"); //This will use the default client where supported
When using the objects, there are generally static methods for Create, Get and List of each entity. Once you have an instance of any entity, you can call the instance methods of that entity to perform additional operations.
var sites = await Site.List(client);
var site = await Site.Get(client, "siteId");
var newSite = await Site.Create(client, new Site(){
Name = "MyTest Site"
});
var sipPeers = await site.GetSipPeers();
site.Delete();
When making making API calls the client can throw an AggregateException
this will normally contain a BandwidthIrisException
. A suggested way to handle the API calls is to catch the AggregateException
that API calls can create and #Handle
the BandwidthIrisException
. Example:
try
{
var site = await Site.Get(client, "siteId");
} catch (AggregateException e)
{
e.Handle((x) =>
{
if(x is BandwidthIrisException)
{
//Do something
return true;
}
return false;
});
}
var query = new Dictionary<string, object>();
query.Add("areaCode", "805");
query.Add("quantity", 3);
var items = await AvailableNpaNxx.List(_client, query);
foreach (AvailableNpaNxx npaNxx in items)
{
Console.WriteLine(string.Format("NpaNxx: {0}",npaNxx.Npa + npaNxx.Nxx));
}
var query = new Dictionary<string, object>();
query.Add("areaCode", "805");
query.Add("quantity", 3);
var result = await AvailableNumbers.List(_client, query);
foreach (string number in result.TelephoneNumberList)
{
Console.WriteLine(string.Format("Number: {0}", number));
}
var query = new Dictionary<string, object>();
query.Add("state", "CA");
query.Add("available", true);
var result = await City.List(_client, query);
foreach (City city in result)
{
Console.WriteLine("City Name: {0}", city.Name);
}
var query = new Dictionary<string, object>();
query.Add("state", "CA");
query.Add("available", true);
var result = await RateCenter.List(query);
foreach (RateCenter rateCenter in result)
{
Console.WriteLine("RateCenter Name: {0}", rateCenter.Name);
}
var query = new Dictionary<string, object>();
query.Add("zip", "27609");
var result = await CoveredRateCenter.List(_client, query);
foreach (CoveredRateCenter rateCenter in result)
{
Console.WriteLine("RateCenter Name: {0}", rateCenter.Name);
}
var result = await Order.Create(_client, new Order
{
Name = "Test Order",
SiteId = "SiteId",
CustomerOrderId = "SomeCustomerId",
LataSearchAndOrderType = new LataSearchAndOrderType
{
Lata = "224",
Quantity = 1
}
});
var order = await Order.Get("orderId");
order.Update()
order.AddNote(var note);
order.GetNotes();
order.GetAreaCodes();
order.GetNpaNxx();
order.GetTotals();
order.GetTns();
order.GetHistory();
var query = new Dictionary<string, object>();
query.Add("page", "1");
query.Add("size", "10");
query.Add("zip", "27516");
OrderListResponse orderListResponse = await Order.List(client, query);
orderListResponse.Orders.TotalCount;
orderListResponse.Orders.Links.First;
orderListResponse.Orders.Links.Next;
orderListResponse.Orders.Links.Last;
orderListResponse.Orders.OrderDetails.Count;
orderListResponse.Orders.OrderDetails[0].CountOfTns;
orderListResponse.Orders.OrderDetails[0].OrderStatus;
orderListResponse.Orders.OrderDetails[0].OrderId;
orderListResponse.Orders.OrderDetails[0].LastModifiedDate;
orderListResponse.Orders.OrderDetails[0].OrderDate;
orderListResponse.Orders.OrderDetails[0].UserId;
orderListResponse.Orders.OrderDetails[0].TelephoneNumberDetailsWithCount.States.Count;
orderListResponse.Orders.OrderDetails[0].TelephoneNumberDetailsWithCount.States[0].Count;
orderListResponse.Orders.OrderDetails[0].TelephoneNumberDetailsWithCount.States[0].State;
orderListResponse.Orders.OrderDetails[0].TelephoneNumberDetailsWithCount.RateCenters.Count;
orderListResponse.Orders.OrderDetails[0].TelephoneNumberDetailsWithCount.RateCenters[0].Count;
orderListResponse.Orders.OrderDetails[0].TelephoneNumberDetailsWithCount.RateCenters[0].RateCenter;
orderListResponse.Orders.OrderDetails[0].TelephoneNumberDetailsWithCount.Cities.Count;
orderListResponse.Orders.OrderDetails[0].TelephoneNumberDetailsWithCount.Cities[0].Count;
orderListResponse.Orders.OrderDetails[0].TelephoneNumberDetailsWithCount.Cities[0].City;
orderListResponse.Orders.OrderDetails[0].TelephoneNumberDetailsWithCount.Tiers.Count;
orderListResponse.Orders.OrderDetails[0].TelephoneNumberDetailsWithCount.Tiers[0].Count;
orderListResponse.Orders.OrderDetails[0].TelephoneNumberDetailsWithCount.Tiers[0].Tier;
orderListResponse.Orders.OrderDetails[0].TelephoneNumberDetailsWithCount.Vendors.Count;
orderListResponse.Orders.OrderDetails[0].TelephoneNumberDetailsWithCount.Vendors[0].Count;
orderListResponse.Orders.OrderDetails[0].TelephoneNumberDetailsWithCount.Vendors[0].VendorId;
orderListResponse.Orders.OrderDetails[0].TelephoneNumberDetailsWithCount.Vendors[0].VendorName;
var application = new Application
{
ApplicationId = "d3e418e9-1833-49c1-b6c7-ca1700f79586",
ServiceType = "Voice-V2",
AppName = "v1",
CallbackCreds = new CallbackCreds
{
UserId = "login123"
},
CallStatusMethod = "GET",
CallInitiatedMethod = "GET",
CallInitiatedCallbackUrl = "https://a.com",
CallStatusCallbackUrl = "https://b.com"
};
var response = await Application.Create(client, application);
var response = await Application.List(client);
var response = await Application.Get(client, applicationId);
var application = new Application
{
AppName = "XgRIdP"
};
var response = await Application.PartialUpdate(client, applicationId, application);
var application = new Application
{
ServiceType = "Voice-V2",
AppName = "v1",
CallbackCreds = new CallbackCreds
{
UserId = "login123"
},
CallStatusMethod = "GET",
CallInitiatedMethod = "GET",
CallInitiatedCallbackUrl = "https://a.com",
CallStatusCallbackUrl = "https://b.com"
};
var response = await Application.FullUpdate(client, applicationId, application);
var response = await Application.Delete(client, applicationId);
var response = await Application.ListAssociatedSippeers(client, applicationId);
For LNP Checker, send one number at a time when using the C# SDK.
try
{
var result = await LnpChecker.Check(client, new string[] { "555555" });
Console.WriteLine(result);
}
catch (Bandwidth.Iris.BandwidthIrisException error)
{
Console.WriteLine(error.Message);
}
catch (Exception e)
{
Exception innerEx = e;
while(innerEx != null)
{
string msg = innerEx.Message;
Console.WriteLine(msg);
innerEx = innerEx.InnerException;
}
}
var data = new PortIn
{
BillingTelephoneNumber = "+1-202-555-0158",
Subscriber = new Subscriber
{
SubscriberType = "BUSINESS",
BusinessName = "Company",
FirstName = "John",
LastName = "Doe",
ServiceAddress = new Address
{
City = "City",
StateCode = "State",
Country = "Country"
}
},
PeerId = sipPeer.Id,
SiteId = site.Id
};
var order = await PortIn.Create(_client, data);
var portInOrder = PortIn.Get("orderId");
var portIn = new PortIn { Id = "1" };
portIn.SetClient(client);
var fileMetadata = new FileMetadata {
DocumentType = "INVOICE",
DocumentName = "docName"
};
var r = portIn.PutFileMetadata("test", fileMetadata).Result;
portInOrder.Update();
portInOrder.Delete();
portInOrder.AddNote(Note n);
portInOrder.GetNotes();
portInOrder.CreateFile(Stream s, string mediaType);
portInOrder.CreateFile(byte[] buffer, string mediaType);
portInOrder.UpdateFile(string fileName, Stream s, string mediaType);
portInOrder.UpdateFile(string fileName, byte[] buffer, string mediaType);
portInOrder.GetFileMetaData(string fileName);
PutFileMetadata(string fileName, FileMetadata fileMetadata);
portInOrder.DeleteFile(string fileName);
portInOrder.GetFiles(bool metaData);
portInOrder.GetFile(string fileName);
var newSite = await Site.Create(_client, new Site()
{
Name = "Csharp Test Site",
Description = "A site from the C# Example",
Address = new Address()
{
HouseNumber = "123",
StreetName = "Anywhere St",
City = "Raleigh",
StateCode = "NC",
Zip = "27609",
AddressType = "Service"
}
});
var sites = awaite Site.List();
site.Delete();
var sipPeerHost = "1.2.3.4";
var newSipPeer = await SipPeer.Create(_client, new SipPeer()
{
IsDefaultPeer = true,
ShortMessagingProtocol = "SMPP",
SiteId = "SiteId,
VoiceHosts = new []
{
new HostData
{
HostName = sipPeerHost
}
},
SmsHosts = new []
{
new HostData
{
HostName = sipPeerHost
}
},
TerminationHosts = new TerminationHost[]
{
new TerminationHost()
{
HostName = sipPeerHost,
Port = 5060
}
}
});
var sipPeer = await SipPeer.Get("sipPeerId");
var sipPeer = await SipPeer.Get("sipPeerId");
sipPeer.Delete();
sipPeer.GetTn(number);
sipPeer.UpdateTns(number, data);
sipPeer.MoveTns(new string[] numbers);
var sipPeerOriginationSettingsResponse = await SipPeer.GetOriginationSettings(siteId, sipPeerId);
var sipPeerOriginationSettings = new SipPeerOriginationSettings
{
VoiceProtocol = "HTTP",
HttpSettings = new HttpSettings
{
HttpVoiceV2AppId = "469ebbac-4459-4d98-bc19-a038960e787f"
}
};
var sipPeerOriginationSettingsResponse = await SipPeer.SetOriginationSettings(siteId, sipPeerId, sipPeerOriginationSettings);
var sipPeerOriginationSettings = new SipPeerOriginationSettings
{
VoiceProtocol = "HTTP",
HttpSettings = new HttpSettings
{
HttpVoiceV2AppId = "469ebbac-4459-4d98-bc19-a038960e787f"
}
};
SipPeer.UpdateOriginationSettings(siteId, sipPeerId, SipPeerOriginationSettings).Wait();
var sipPeerTerminationSettingsResponse = await SipPeer.GetTerminationSetting(siteId, sipPeerId);
var sipPeerTerminationSettings = new SipPeerTerminationSettings
{
VoiceProtocol = "HTTP",
HttpSettings = new HttpSettings
{
HttpVoiceV2AppId = "469ebbac-4459-4d98-bc19-a038960e787f"
}
};
var sipPeerTerminationSettingsResponse = await SipPeer.GetTerminationSetting(siteId, sipPeerId, sipPeerTerminationSettings);
var sipPeerTerminationSettings = new SipPeerTerminationSettings
{
VoiceProtocol = "HTTP",
HttpSettings = new HttpSettings
{
HttpVoiceV2AppId = "469ebbac-4459-4d98-bc19-a038960e787f"
}
};
SipPeer.UpdateTerminationSettings(client, siteId, sipPeerId, SipPeerTerminationSettings).Wait();
var sipPeerSmsFeatureResponse = await SipPeer.GetSMSSetting(siteId, sipPeerId);
var sipPeerSmsFeature = new SipPeerSmsFeature
{
SipPeerSmsFeatureSettings = new SipPeerSmsFeatureSettings
{
TollFree = true
},
SmppHosts = new SmppHost[]
{
new SmppHost
{
HostName = "Host"
}
}
};
var sipPeerSmsFeatureResponse = await SipPeer.CreateSMSSettings(siteId, sipPeerId, sipPeerSmsFeature);
var sipPeerSmsFeature = new SipPeerSmsFeature
{
SipPeerSmsFeatureSettings = new SipPeerSmsFeatureSettings
{
TollFree = true
},
SmppHosts = new SmppHost[]
{
new SmppHost
{
HostName = "Host"
}
}
};
var sipPeerSmsFeatureResponse = await SipPeer.UpdateSMSSettings(siteId, sipPeerId, sipPeerSmsFeature);
SipPeer.DeleteSMSSettings(siteId, sipPeerId).Wait();
var MmsFeatureResponse = await SipPeer.GetMMSSetting(siteId, sipPeerId);
var mmsFeature = new MmsFeature
{
Protocols = new Protocols
{
MM4 = new MM4
{
Tls = "OFF"
}
}
};
var MmsFeatureResponse = await SipPeer.CreateMMSSettings(siteId, sipPeerId, mmsFeature);
var mmsFeature = new MmsFeature
{
Protocols = new Protocols
{
MM4 = new MM4
{
Tls = "OFF"
}
}
};
SipPeer.UpdateMMSSettings(siteId, sipPeerId, MmsFeature).Wait();
SipPeer.DeleteMMSSettings(siteId, sipPeerId).Wait();
var applicationsSettingsResponse = await SipPeer.GetApplicationSetting(siteId, sipPeerId);
var applicationSettings = new ApplicationsSettings
{
HttpMessagingV2AppId = "c3b0f805-06ab-4d36-8bf4-8baff7623398"
};
SipPeer.UpdateApplicationSettings(siteId, sipPeerId, applicationSettings).Wait();
SipPeer.RemoveApplicationSettings(siteId, sipPeerId).Wait();
var subscription = await Subscription.Create(new Subscription()
{
OrderType = "orders",
OrderId = "100",
EmailSubscription = new EmailSubscription
{
Email = "test@test",
DigestRequested = "NONE"
}
};
var subscription = await Subscription.Get("subscriptionId");
var list = await Subscription.List(new Dictionary<string,object>{{"orderType", "orders"}})
subscription.Update();
subscription.Delete();
var result = await Tn.Get("9195551212");
var details = await result.GetDetails();
var result = await Tn.List(new Dictionary<string, object>{{{"npa", "919"}})
var item = await TnReservation.Create(new TnReservation()
{
AccountId = "accountId",
ReservedTn = "9195551212",
ReservationExpires = 0
};
var reservation = await TnReservation.Get("Id");
reservation.Delete();
var dlda = new Dlda
{
CustomerOrderId = "Your Order Id",
DldaTnGroups = new[]{
new DldaTnGroup{
TelephoneNumbers = new TelephoneNumbers {Numbers = new[]{"9195551212"}},
SubscriberType = "RESIDENTIAL",
ListingType = "LISTED",
ListingName = new ListingName{
FirstName = "John",
LastName = "Smith"
},
ListAddress = true,
Address = new Address{
HouseNumber = "123",
StreetName = "Elm",
StreetSuffix = "Ave",
City = "Carpinteria",
StateCode = "CA",
Zip = "93013",
AddressType = "DLDA"
}
}
}
};
await Dlda.Create(dlda);
var dlda = await Dlda.Get(id);
var list = await Dlda.GetHistory();
var item = new Lidb
{
CustomerOrderId = "A Test order",
LidbTnGroups = new[] {
new LidbTnGroup{
TelephoneNumbers = new []{"8048030097", "8045030098"},
SubscriberInformation = "Joes Grarage",
UseType = "RESIDENTIAL",
Visibility = "PUBLIC"
}
}
};
await Lidb.Create(item);
var item = await Lidb.Get(id);
var list = await Lidb.List();
var item = new TnLineOptions
{
TelephoneNumber = "5209072451",
CallingNameDisplay = "off"
};
var numbers = await LineOptionOrder.Create(item);
var list = await InServiceNumber.List(new Dictionary<string, object>{{"city", "Cary"}});
var totals = await InServiceNumber.GetTotals();
var list = await DiscNumber.List(new Dictionary<string, object>{{"type", "NPA"}});
var totals = await DiscNumber.GetTotals();
var list = await Host.List(new Dictionary<string,object>{{"type", "SMS"}});
var order = new ImportTnOrder
{
OrderId = "fbd17609-be44-48e7-a301-90bd6cf42248",
AccountId = "account",
SipPeerId = 1,
SiteId = 2
};
var response = await ImportTnOrder.Create(client, order);
var response = await ImportTnOrder.List(client, new Dictionary<string, object> { { "accountId", "1" } });
var response = await ImportTnOrder.Get(client, orderId);
var response = await ImportTnOrder.GetHistory(client, orderId )
var order = new RemoveImportedTnOrder
{
OrderId = "fbd17609-be44-48e7-a301-90bd6cf42248",
AccountId = "account"
};
var response = await RemoveImportedTnOrder.Create(client, order);
var response = await RemoveImportedTnOrder.List(client, new Dictionary<string, object> { { "accountId", "1" } });
var response = await RemoveImportedTnOrder.Get(client, orderId);
var response = await RemoveImportedTnOrder.GetHistory(client, orderId )
var payload = new ImportTnCheckerPayload
{
TelephoneNumbers = new TelephoneNumber[]
{
new TelephoneNumber
{
FullNumber = "3032281000"
}
}
};
var response = await ImportTnChecker.Create(client, payload);
var csr = new Csr
{
AccountId = "accountId"
//Additional information
};
var response = await Csr.Create(client, csr);
var response = await Csr.Get(client, orderId);
var csr = new Csr
{
AccountId = "new accountId"
//Additional information
};
var response = await Csr.Replace(client, orderId, csr);
var response = await Csr.ListNotes(client, orderId);
var note = new Note
{
Description = "Description goes here"
};
Csr.CreateNote(client, orderId, note);
var note = new Note
{
Description = "Updated description goes here"
};
Csr.UpdateNote(client, orderId, noteId, note);
var result = await EmergencyNotification.GetRecipients(client, orderId);
var result = await EmergencyNotification.ListRecipients(client, new Dictionary<string, Object>
{
{"EnrNotificationType", "SMS" }
});
var result = await EmergencyNotification.CreateRecipients(client, new EmergencyNotificationRecipient
{
ModifiedByUser = "testuser",
Type = "EMAIL",
EmailAddress = "[email protected]"
});
var result = await EmergencyNotification.UpdateRecipients(client, id, new EmergencyNotificationRecipient
{
ModifiedByUser = "testuser",
Type = "EMAIL",
EmailAddress = "[email protected]"
});
EmergencyNotification.DeleteRecipients(client, id).Wait();
var result = await EmergencyNotification.GetGroupOrders(client, id);
var result = await EmergencyNotification.ListGroupOrders(client, new Dictionary<string, Object>
{
{"EnrNotificationType", "TTS" }
});
var result = await EmergencyNotification.CreateGroupOrders(client, new EmergencyNotificationGroupOrder
{
CustomerOrderId = "test",
AddedEmergencyNotificationGroup = new EmergencyNotificationGroup
{
CreatedBy = "samwise"
}
});
var result = await EmergencyNotification.GetGroups(client, id);
var result = await EmergencyNotification.ListGroups(client, new Dictionary<string, Object>
{
{"EnrDetails", "true" },
{"EnrEmailAddress", "[email protected]" }
});
var result = await EmergencyNotification.GetEndpointOrders(client, id);
var result = await EmergencyNotification.ListEndpointOrders(client, new Dictionary<string, Object>
{
{"EepTns", "404" }
});
var result = await EmergencyNotification.CreateEndpointOrders(client, endpointOrder);
var response = await Aeui.Get(client, id);
var response = await Aeui.List(client);
Create TN Option order(s) to assign line features to the telephone number
var order = new TnOptionOrder
{
CustomerOrderId = "customerOrderId",
TnOptionGroups = new List<TnOptionGroup>
{
new TnOptionGroup {
PortOutPasscode = "a1b2c3",
TelephoneNumbers = new List<string>
{
"2018551020",
"2018551025"
}
}
}
};
var result = await TnOptions.Create(client, order);
var order = new TnOptionOrder
{
CustomerOrderId = "customerOrderId",
TnOptionGroups = new List<TnOptionGroup>
{
new TnOptionGroup {
Sms = "on",
TelephoneNumbers = new List<string>
{
"2018551020",
"2018551025"
}
}
}
};
var result = await TnOptions.Create(client, order);
var order = new TnOptionOrder
{
CustomerOrderId = "customerOrderId",
TnOptionGroups = new List<TnOptionGroup>
{
new TnOptionGroup {
CallForward = "6042661720",
TelephoneNumbers = new List<string>
{
"2018551020",
"2018551025"
}
}
}
};
var result = await TnOptions.Create(client, order);
TnOptionOrder response = null;
try{
response = await TnOptions.Get(client, orderId);
} catch (Exception ex) {
//No error thrown
}
Console.WriteLine(response.OrderCreateDate); //"2016-01-15T11:22:58.789Z"
TnOptionOrder response = null;
try{
response = await TnOptions.Get(client, orderId);
} catch (Exception ex) {
if (ex.InnerException is BandwidthIrisException)
{
var exInner = (BandwidthIrisException)ex.InnerException;
Console.WriteLine(exInner.Message); //"Telephone number is not available"
Console.WriteLine(exInner.Body); // <TnOptionOrders><TotalCount>2</TotalCount><TnOptionOrder>..........</TnOptionOrder></TnOptionOrders>
}
}
var result = await TnOptions.List(client, new Dictionary<string, Object>
{
{"status", "9199918388" }
});