using RestAPI;
using System;
namespace TestRestAPI.Examples {
    class SendSMS {
        static void Main(string[] args) {
            RestClient rClient = new RestClient("MyUser", "MyPass", RestClient.ENV_PRODUCTION);
            try {
                rClient.sendSMS("Hello SMS World!", "351939714724", "07860021976", 72, "", "", null);
            } catch (RestClientException e) {
                Console.WriteLine(e.Message);
            }
        }
    }
}
using System;
using RestAPI;
namespace TestRestAPI.Examples {
    class CheckBalance {
        static void Main(string[] args) {
            RestClient rClient = new RestClient("MyUser", "MyPass", RestClient.ENV_PRODUCTION);
            try {
                int creditsAvailable = rClient.getCredits();
                Console.WriteLine("Account have {0} credits.", creditsAvailable);
            }
            catch (RestClientException e) {
                Console.WriteLine(e.Message);
            }
        }
    }
}
using System;
using RestAPI;
using System.Collections;
namespace TestRestAPI.Examples {
    class DeliveryReports {
        static void Main(string[] args) {
            RestClient rClient = new RestClient("MyUser", "MyPass", RestClient.ENV_PRODUCTION);
            try {
                DeliveryReport[] reports = rClient.getDeliveryReport("all");
                foreach (DeliveryReport report in reports) {
                    Console.WriteLine(report);
                    foreach (Hashtable row in report.Rows) {
                        Console.WriteLine("\tMessage ID: {0}", row["message_id"]);
                        Console.WriteLine("\tLast Updated: {0}", row["last_updated"]);
                        Console.WriteLine("\tMobile Number: {0}", row["mobile_number"]);
                        Console.WriteLine("\tStatus: {0}", row["status"]);
                        Console.WriteLine("\tCustom {0}", row["custom"]);
                    }
                }
            }
            catch (RestClientException e) {
                Console.WriteLine(e.Message);
            }
        }
    }
}
using System;
using RestAPI;
namespace TestRestAPI.Examples {
    class CreateAccount {
        static void Main(string[] args) {
            RestClient rClient = new RestClient("MyUser", "MyPass", RestClient.ENV_PRODUCTION);
            try {
                rClient.createSubAccount("My client", "447000000000", null, null, null, null, false);
            }
            catch (RestClientException e) {
                Console.WriteLine(e.Message);
            }
        }
    }
}
using System;
using RestAPI;
namespace TestRestAPI.Examples {
    class CreditTransfer {
        static void Main(string[] args) {
            RestClient rClient = new RestClient("MyUser", "MyPass", RestClient.ENV_PRODUCTION);
            try {
                rClient.transferCreditsToUser(5000, "targetAPIusername", "targetAPIpassword");
            }
            catch (RestClientException e) {
                Console.WriteLine(e.Message);
            }
        }
    }
}
To complete your code you should add some error handing, to catch exceptions. All you need to do is put the wrapper function calls in a try-catch block as follows.

 

using System;
using RestAPI;
using System.Collections;
namespace TestRestAPI.Examples {
    class ErrorCapture {
        static void Main(string[] args) {
            RestClient rClient = new RestClient("MyUser", "MyPass", RestClient.ENV_PRODUCTION);
            try {
                rClient.sendSMS("Hello SMS World!", "351939714724", "07860021976", 72, "", "", null);
                // if the send fails, execution jumps to the start of the catch-block
                int creditsAvailable = rClient.getCredits();
                Console.WriteLine("Account have {0} credits.", creditsAvailable);
            }
            catch (RestClientException e) {
                Console.WriteLine(e.Message);
                foreach (DictionaryEntry de in rClient.getLastErrors())
                    Console.WriteLine("Error {0}: {1}", de.Key, de.Value);
            }
        }
    }
}
	

It is up to you to decide how to handle the errors. We also recommend that you log them for debugging purposes.

 

 

 

 

Our example code is an illustration of how you might integrate with our systems and is not certified for production environments. You are responsible for testing and QA.