Skip to content

Official .NET client for the inMobile API

License

Notifications You must be signed in to change notification settings

inMobile/inMobile-.NET-API-Client

Repository files navigation

inMobile-.NET-API-Client

Official .NET client for the inMobile V4 API

You can always download the latest release as a NuGet package here.

Create a client

var apiKey = new InMobileApiKey("My secret key");
var client = new InMobileApiClient(apiKey: apiKey);

Sending SMS messages

SMS: Send messages

// Wrap the following in a try/catch - should also be done for all calls to the api
try
{
    var result = client.SmsOutgoing.SendSmsMessages(new List<OutgoingSmsMessageCreateInfo>() {
        new OutgoingSmsMessageCreateInfo(to: "4511223344", text: "Hello world", from: "FancyShop", statusCallbackUrl: null)
    });
    // statusCallbackUrl: Specify a url if you want report callbacks
}
catch (InMobileApiException ex)
{
    Console.WriteLine("Unexpected exception: " + ex.Message);
}

SMS: Send messages using template

var result = client.SmsOutgoing.SendSmsMessagesUsingTemplate(new OutgoingSmsTemplateCreateInfo(
    templateId: new SmsTemplateId("MY-TEMPLATE-ID"),
    new List<OutgoingSmsTemplateMessageCreateInfo>
    {
        new OutgoingSmsTemplateMessageCreateInfo(
            placeholders: new Dictionary<string, string>(),
            to: "4511223344",
            statusCallbackUrl: null)
    }));
// statusCallbackUrl: Specify a url if you want report callbacks

SMS: Cancel messages

var result = client.SmsOutgoing.CancelMessages(new List<OutgoingMessageId> 
{ 
    new OutgoingMessageId("MESSAGE-ID-1"),
    new OutgoingMessageId("MESSAGE-ID-2")
});

SMS: Pull message statuses

Note that this is the PULL version of getting statuses.

var reports = client.SmsOutgoing.GetStatusReports(limit: 10); // Limit must be between 1 and 250.

Blacklist

Blacklist: Add

var blacklistEntry = client.Blacklist.Add(new NumberInfo(countryCode: "45", phoneNumber: "11223344"));

Blacklist: Get all

var allBlacklistEntries = client.Blacklist.GetAll();

Blacklist: Get by id

var blacklistEntry = client.Blacklist.GetById(blacklistEntryId: new BlacklistEntryId("7b69cc8c-aafd-4697-917a-6ecd314def5e"));

Blacklist: Get by number

var blacklistEntry = client.Blacklist.GetByNumber(new NumberInfo(countryCode: "45", phoneNumber: "12345678"));

Blacklist: Remove by id

client.Blacklist.RemoveById(blacklistEntryId: new BlacklistEntryId("f0d0767b-5f9e-4d33-8155-1c29fefd8238"));

Blacklist: Remove by number

client.Blacklist.RemoveByNumber(new NumberInfo(countryCode: "45", phoneNumber: "12345678"));

Lists and recipients

Lists: Create

var createdList = client.Lists.CreateList(name: "My list name");

Lists: Get all

var allLists = client.Lists.GetAllLists();

Lists: Get by id

var list = client.Lists.GetListById(listId: new RecipientListId("af20c37d-c9d2-4343-8c46-8c8fbc5c5b14"));

Lists: Update (without loading the list first)

var updatedList = client.Lists.UpdateList(new RecipientListUpdateInfo(
                        listId: new RecipientListId("ff5d0e4f-02a3-4930-8bb8-11da43bd7ab8"),
                        name: "New list name"));

This will reduce the network latency during the whole operation and considerably reduce the risk of lost updates compared to the next example with (load, update, save).

Lists: Update (load, update, save)

var list = client.Lists.GetListById(listId: new RecipientListId("ff5d0e4f-02a3-4930-8bb8-11da43bd7ab8"));
            list.Name = "New list name";
            client.Lists.UpdateList(list);

There could be a risk of lost updates, if multiple sources manipulate the recipients at the same time.

Lists: Delete by id

client.Lists.DeleteListById(listId: new RecipientListId("1b6415e9-9f94-419a-9d9b-21974f6586e7"));

Recipients: Create

var newRecipient = new RecipientCreateInfo(listId: new RecipientListId("a2e2dfee-4a45-44b7-98fd-223399c31dba"),
                                           numberInfo: new NumberInfo(countryCode: "45", phoneNumber: "11223344"));
newRecipient.Fields.Add("email", "some_email@mywebsite.com"); // Optional
var createdRecipient = client.Lists.CreateRecipient(recipient: newRecipient);

Recipients: Get all

var allRecipients = client.Lists.GetAllRecipientsInList(listId: new RecipientListId("6e076753-3d8e-4603-8ff8-66b6b6d8ff82"));

Recipients: Get by id

var recipient = client.Lists.GetRecipientById(listId: new RecipientListId("6e076753-3d8e-4603-8ff8-66b6b6d8ff82"),
                                              recipientId: new RecipientId("d317de6f-234c-401d-9bd8-6eaa3b5f3b35"));

Recipients: Get by number

var recipient = client.Lists.GetRecipientByNumber(
                                listId: new RecipientListId("0dd17a28-c392-486c-8f8d-8ab897b07c39"),
                                numberInfo: new NumberInfo(countryCode: "45",
                                phoneNumber: "12345678"));

Recipients: Update (without loading the recipient first)

client.Lists.UpdateRecipient(new RecipientUpdateInfo(
                             recipientId: new RecipientId("d317de6f-234c-401d-9bd8-6eaa3b5f3b35"),
                             listId: new RecipientListId("6e076753-3d8e-4603-8ff8-66b6b6d8ff82"),
                             numberInfo: new NumberInfo("33", "999999"),
                             fields: new Dictionary<string, string>() {
                               { "firstname", "Bill" },
                               { "Custom2", "Val2" }
                             }));

This will reduce the network latency during the whole operation and considerably reduce the risk of lost updates compared to the next example with (load, update, save).

Recipients: Update (load, update, save)

// Load recipient
var recipient = client.Lists.GetRecipientById(listId: new RecipientListId("6e076753-3d8e-4603-8ff8-66b6b6d8ff82"),
                                                          recipientId: new RecipientId("d317de6f-234c-401d-9bd8-6eaa3b5f3b35"));
// Update desired values (In the example we update the msisdn and the email)
recipient.NumberInfo = new NumberInfo(countryCode: "45", phoneNumber: "99998888");
recipient.Fields["email"] = "some_new_email@mydomain.com";

There could be a risk of lost updates, if multiple sources manipulate the recipients at the same time.

Recipients: Delete by id

client.Lists.DeleteRecipientById(listId: new RecipientListId("8b481e37-8709-455a-9b74-74efe99ac7de"),
                                 recipientId: new RecipientId("a99317fc-141a-4848-8672-367750bc61b0"));

Recipients: Delete by number

client.Lists.DeleteRecipientByNumber(listId: new RecipientListId("8b481e37-8709-455a-9b74-74efe99ac7de"),
                                     numberInfo: new NumberInfo(
                                        countryCode: "45",
                                        phoneNumber: "12345678"));

SMS Templates

SMS Templates: Get all

var allSmsTemplates = client.SmsTemplates.GetAll();

SMS Templates: Get by id

var smsTemplate = client.SmsTemplates.GetById(new SmsTemplateId("MY-TEMPLATE-ID"));

SMS GDPR

SMS GDPR: Create deletion request

var result = client.SmsGdpr.CreateDeletionRequest(new NumberInfo("45", "11223344"));

Tools

Tools: Parse mobile numbers

var result = client.Tools.ParsePhoneNumbers(new List<ParsePhoneNumberInfo> 
{ 
    new ParsePhoneNumberInfo("DK", "+45 11 22 33 44") 
});

About

Official .NET client for the inMobile API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages