Consuming RESTful API to get Bank Details using IFSC code in C#

Introduction

Suppose If you assigned the task to write code to get bank details using IFSC code. Details may be bank name, ifsc code, micr(Magnetic Ink Character Recognition), branch, address, contact, city, district and state. What you’ll do ?

All bank ifsc codes are regularly updated on RBI website, you can download in Excel sheet and re arrange it. and same can be used in your website but this is not easy task to gather such a large data and integrate in your database to get details. So you just need only a RESTful API to accomplish this task but unfortunately there is no such API which can provide updated details.  ifsc cods are obtain from different banks by RBI  every month, new banks branches are go to add every time . so technically its very hard to maintain the all bank IFSC list.

You can try Datayuge IFSC Code API. There database is weekly updated and service is free without any restriction.

How to Consume API :

In order to consume the API, you need an API Key (get the API key here)
Once you register, you’ll get API there in dashboard, containing the key.

API Root : https://ifsc.datayuge.com/api/v1/
Example Request Route #1: https://ifsc.datayuge.com/api/v1/{IFSC_CODE}
Request Type: GET
API Authentication Header : DY-X-Authorization: {API KEY}
Response Type: JSON
Sample Response:

get Bank Details using IFSC code

get Bank Details using IFSC code

Let test this API first using fiddler. Follow steps described in below image.

Using the C# Code :

In this tip, I will show you consumption of RESTful API in client applications.
I found https://ifsc.datayuge.com/api/v1/ RESTful API which is running online. I tried to consume that live service in console application.
Code to consume JSON data of bank details after passing IFSC Code

     public void ReadBankDetails(string ifsc_code)
        {
            using (var client = new WebClient())
            {
                client.Headers.Add("DY-X-Authorization: API_KEY");
                var result = client.DownloadString("https://ifsc.datayuge.com/api/v1/" + ifsc_code.Trim());

                Console.WriteLine(result);            
            }
        }
    }
It will print – {“bank”:”Abhyudaya Cooperative Bank Limited”,”ifsc”:”ABHY0065001″,”micr”:”400065001″,”branch”:”Rtgs-Ho”,”address”:”Abhyudaya Bank Bldg-, B-No-71, Nehru Nagar, Kurla (e), Mumbai-400024″,”contact”:”25260173E7″,”city”:”Greater Mumbai”,”district”:”Mumbai”,”state”:”Maharashtra”}

But this is JSON Data and you may want to convert it into object so you can print each record as per your need. To accomplish that you have to Deserialize JSON Data. Ok Fine! but how to do ?

Create a class and have all required properties that you want to consume from API.

 public class BankDet
    {
        public string bank { get; set; }
        public string ifsc { get; set; }
        public string micr { get; set; }
        public string branch { get; set; }
        public string address { get; set; }
        public string contact { get; set; }
        public string city { get; set; }
        public string district { get; set; }
        public string state { get; set; }
    }

Now, Add Newtonsoft.Json package in your application and write code given below to parse JSON data to appropriate property of BankDet class.

        var bankData = JsonConvert.DeserializeObject<BankDet>(result); // result is var containing fetched JSON  
        Console.WriteLine(bankData.bank);

Complete Code :

using System;
using System.Net;
using Newtonsoft.Json;

namespace Get_BankDetails_Using_IFSC_Code
{
    class Program
    {
        public class BankDet
        {
            public string bank { get; set; }
            public string ifsc { get; set; }
            public string micr { get; set; }
            public string branch { get; set; }
            public string address { get; set; }
            public string contact { get; set; }
            public string city { get; set; }
            public string district { get; set; }
            public string state { get; set; }
        }
        public void ReadBankDetails(string ifsc_code)
        {
            using (var client = new WebClient())
            {
                client.Headers.Add("DY-X-Authorization: API_KEY");
                var result = client.DownloadString("https://ifsc.datayuge.com/api/v1/" + ifsc_code.Trim());                

                var bankData = JsonConvert.DeserializeObject<BankDet>(result);
                string printres = string.Format("Bank Name : {0}\nIFSC Code : {1}\nMICR : {2}\nBranch : {3}\nAddress : {4}\nContact : {5}\nCity : {6}\nDistrict : {7}\nState : {8}", bankData.bank, bankData.ifsc, bankData.micr, bankData.branch, bankData.address, bankData.contact, bankData.city, bankData.district, bankData.state);
                Console.WriteLine(printres);
            }
        }
        static void Main(string[] args)
        {
            Program obj = new Program();          
            obj.ReadBankDetails("ABHY0065001");
            Console.ReadLine();
        }
    }
}

Output :

Share Knowledge
This entry was posted in C#, TIPS/TRICKS, WEB API and tagged , , , . Bookmark the permalink.

5 Responses to Consuming RESTful API to get Bank Details using IFSC code in C#

  1. Very interesting points you have remarked, appreciate it for putting up.

  2. K Roy says:

    Thanks for letting me know about this service. I was looking for such service where I can get basic details using IFSC code.

    • We are glad that this article helped you. Kindly subscribe our blog for more interesting stuffs. If you are looking for any specific article, kindly let us know in the comment section. Thanks

  3. Rahul says:

    Very nice guide. I have also used this method to get IFSC data on one my clients’s website yobola.com

Leave a Reply

Your email address will not be published. Required fields are marked *