07 June 2015

Using Telstra API to send SMS in ASP.NET

Telstra (https://dev.telstra.com/) is pushing their own API and as a part of the plan, it is giving away 1000 free SMS per month with the limit of 100 per day.

After a simple register and set up, wait about 1 hour for get "MyAPP" approved, it is ready to go.



It requests an access token with your own "key" and "secret" first which expires in 1 hour. Then we need to pass in this token with all the request we are going to make.
The documentation is simple, straight forward and all the sample code is hosted on github. I write a quick C# to test it out and it works well!

public string GetAccessToken()
{
    const string consumerKey = "{yourkey}";
    const string consumerSecret = "{secret}";
    string url =string.Format("https://api.telstra.com/v1/oauth/token?client_id={0}&client_secret={1}&grant_type=client_credentials&scope=SMS", consumerKey, consumerSecret);

    using (var webClient = new System.Net.WebClient())
    {
        var json = webClient.DownloadString(url);
        var obj = JObject.Parse(json);
        return obj.GetValue("access_token").ToString();
     }
}
public string SendSms(string token, string recipientNumber, string message)
{
     try
     {
        using (var webClient = new System.Net.WebClient())
        {
            webClient.Headers.Clear();
            webClient.Headers.Add(HttpRequestHeader.ContentType, @"application/json");
            webClient.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + token);

            string data = "{\"to\":\"" + recipientNumber + "\", \"body\":\"" + message + "\"}";
            var response = webClient.UploadData("https://api.telstra.com/v1/sms/messages", "POST", Encoding.Default.GetBytes(data));
            var responseString = Encoding.Default.GetString(response);
            var obj = JObject.Parse(responseString);
            return obj.GetValue("messageId").ToString();
                    // Now parse with JSON.Net
        }
     }
     catch (Exception e)
     {
        Console.WriteLine(e.Message);
     }
        return string.Empty;
 }

28 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. you might not even be around a TV. our other option for watching Television on a regular cable or satellite box is to do so online hotstickybun

    ReplyDelete
  3. Everyone carries their mobile wherever they go and involuntarily read any new incoming message. So your ad message will be immediately viewed and so SMS marketing is particularly useful for time-sensitive marketing campaigns.
    http://www.padisoft.org

    ReplyDelete
  4. In today's competitive business arena, you need to have a regular interaction with the customers to avoid losing potential customers padisoft.org

    ReplyDelete
  5. The fact that SMS also provides an enormous opportunity for companies to interact with their customers, is not really well known.padisoft.org

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. What could fill somebody's heart with joy other than perusing such perfectly created blog, for example, this.
    best reverse phone number lookup review

    ReplyDelete
  8. When it comes to typical tech enterprising, a business is either an SME or a startup, categorically.best tablets under 302

    ReplyDelete
  9. I definitely loved every little bit of it. I have you bookmarked your site to check out the new stuff you post. vpnveteran

    ReplyDelete
  10. Awesome bit of composing, I extremely loved the manner in which you featured some extremely critical and huge focuses like SMS Sending Using ASP.NET. I value your work.Bulk SMS API

    ReplyDelete
  11. Impressive web site, Distinguished feedback that I can tackle. I am moving forward and may apply to my current job as a pet sitter, which is very enjoyable, but I need to additional expand. Regards maggiori informazioni

    ReplyDelete
  12. This is very interesting content! I have thoroughly enjoyed reading your points and have come to the conclusion that you are right about many of them. You are great. gbwhatsapp ios

    ReplyDelete
  13. There are a lot of blogs and articles out there on this topic, but you have acquired another side of the subject. This is reliable content thank you for sharing it. die besten vpn

    ReplyDelete
  14. You managed to hit the nail upon the top and also defined out the whole thing without having side effect , people could take a signal. Will likely be back to get more. Thanks
    Tangki Panel

    ReplyDelete
  15. I needed to create you one very little observation to finally thank you so much the moment again over the wonderful guidelines you have contributed in this case. It’s really tremendously open-handed of people like you to make unreservedly just what many individuals would’ve sold as an electronic book to help with making some bucks on their own, even more so considering the fact that you might well have done it in the event you wanted. The secrets as well acted to be the fantastic way to recognize that many people have the identical dreams the same as my personal own to figure out way more with reference to this problem. I believe there are many more fun instances in the future for individuals that examine your blog post.
    Jual Septic Tank

    ReplyDelete
  16. I definitely enjoying every little bit of it. It is a great website and nice share. I want to thank you. Good job! You guys do a great blog, and have some great contents. Keep up the good work the best vpn

    ReplyDelete
  17. Thank you again for all the knowledge you distribute,Good post. I was very interested in the article, it's quite inspiring I should admit. I like visiting you site since I always come across interesting articles like this one.Great Job, I greatly appreciate that.Do Keep sharing! Regards, https://internetprivatsphare.at/orf-streamen-im-ausland/

    ReplyDelete
  18. You guardians do an astounding web diary, and have some unfathomable substance. Continue doing extraordinary. click here

    ReplyDelete
  19. Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained!
    Mason Soiza

    ReplyDelete
  20. Extremely intriguing online journal. A lot of web journals I see nowadays don't generally give anything that I'm keen on, however I'm most definitely inspired by this one. Recently felt that I would post and let you know. Arinda IT Services

    ReplyDelete
  21. Awesome review, I am a major devotee to remarking on web journals to educate the web journal scholars realize that they've added something beneficial to the internet!..  https://vpnveteran.com/

    ReplyDelete
  22. I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post. Skype Offline Installer

    ReplyDelete
  23. When you are searching for a gps locator for children, you should search for a couple of highlights. sms bomber iphone

    ReplyDelete
  24. SMS marketing allows the user to send bulk messages easily and quickly to various groups of people.smm reseller panel

    ReplyDelete
  25. Hi there, I found your blog via Google while searching for such kinda informative post and your post looks very interesting for me. https://www.lesmeilleursvpn.com

    ReplyDelete
  26. Incredible Article it its truly instructive and inventive update us as often as possible with new upgrades. its was truly important. much obliged.  besuche die Website

    ReplyDelete
  27. That appears to be excellent however i am still not too sure that I like it. At any rate will look far more into it and decide personally! https://internetprivatsphare.ch

    ReplyDelete
  28. I have used a lot of juicers in the past and I created this blog to help juice lovers make the right decision in choosing the type of juicer that best fit their needs. There are several good masticating juicers to choose from.  lemigliorivpn.com

    ReplyDelete

WFFM Web form for marketer fail to submit in Sitecore

I have setup a standard form using WFFM in Sitecore 8.2. It always fail when submit. Error as below, Error: Exception: System.Data.DataE...