IRCTC or the Indian Railways Catering and Tourism Corporation is the major online ticketing web portal which is primarily handled by the Indian Railways itself. It is the only official online portal to book train tickets online.
The web portal is heavily encrypted. So, you need to create a profile in order to access the website completely and book tickets for your journey in the future. The basic details that you need to create a profile are as follows:
- Name
- Username
- Password
- Email ID
- Mobile Number etc.
All of these should be valid and unique in order to create your profile successfully. No two values must be used elsewhere at any point in time. Repeated values will ensure that your profile is not created, unfortunately.
Once you are done with the profile creation, you can log in and specify your filters to pinpoint your journey details. This information will show you the number of trains which are helpful for your claim only. Those are:
- From
- To
- Date of Journey
- Class of Journey
As you can see, From and To options talk about the Source and Destination stations of your journey respectively. Date of Journey and Class of Journey are pretty much self-explanatory.
Later, after choosing the correct train, you have to fill in other important credentials such as:
- Full Name
- Age
- Gender
- Berth Preference
- Food Choice (For Premium Trains)
- Senior Citizen or Not etc.
These details will authenticate the ticket on your name. However, filling these up everytime is a tedious task. Hence, IRCTC Magic Autofill will help you with hastening the process.
It is a safe browser plugin which will fill in your information with just a click. Afterwards, you need to finish the ticket booking by paying the price through various online transaction options available.
Third-Party Railways API Source Code
As the name of the heading suggests, here is the third-party source code in numerous programming languages. These codes will ascertain you of many services of the Indian Railways such as checking the PNR status and all. The multiple examples are as follows:
C#:
C# is a crossbreed of C and C++. It is a Microsoft programming language elaborated to encounter with Sun’s Java language.
C# is an object-oriented programming language applied with XML-based Web services on the .NET platform and intended for enhancing fecundity in the expansion of Web applications.
1 2 3 4 5 6 7 8 9 10 11 |
string html = string.Empty; string url = "Enter Http API here"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.AutomaticDecompression = DecompressionMethods.GZip; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) using (Stream stream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(stream)) { html = reader.ReadToEnd(); } Console.WriteLine(html); |
PHP:
PHP is a script language and interpreter. It is a freely available interpreter and it is used principally on Linux Web servers. PHP, formerly descended from Personal Home Page Tools, now stands for PHP: Hypertext Preprocessor.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
< ?php //API URL $url="Enter http API here"; // init the resource $ch = curl_init();//Ignore SSL certificate verification curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); //get response $output = curl_exec($ch); //Print error if any if(curl_errno($ch)) { echo 'error:' . curl_error($ch); } curl_close($ch); echo $output; ?> |
Android:
Android is a mobile operating system which was developed by Google. It is one of the most popular operating systems after Windows and iOS. A lot of mobile phones, tablets, TVs etc work on Android itself.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
URLConnection myURLConnection=null; URL myURL=null; BufferedReader reader=null; //encoding message String encoded_message=URLEncoder.encode(message); //Send SMS API String mainUrl="Enter http API here"; try { //prepare connection myURL = new URL(mainUrl); myURLConnection = myURL.openConnection(); myURLConnection.connect(); reader= new BufferedReader(new InputStreamReader(myURLConnection.getInputStream())); //reading response String response; while ((response = reader.readLine()) != null) //print response Log.d("RESPONSE", ""+response); //finally close connection reader.close(); } catch (IOException e) { e.printStackTrace(); } |
iOS:
iOS is the operating system which was developed by Apple. It is one of the most popular operating systems available in the market, strongly competing with Windows from Microsoft.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import UIKit import Alamofire class IndianRailAPI: UIViewController { //make a closure which keeps a check on the status of data download typealias DonwloadComplete = () -> () override func viewDidLoad() { super.viewDidLoad() self.downloadIndianRailAPIData { //update the UI with Parsed data here } } func downloadIndianRailAPIData(completed: @escaping DonwloadComplete){ //Download the API related JSON and Parse it for required info here //API_URL to get data from let TRAIN_ROUTE_URL = "enter http API here" let API_URL = URL(string: TRAIN_ROUTE_URL) //Using the Alamofire Pod the pull the data Alamofire.request(API_URL!).responseJSON { (response) in let result = response.result //print the JSON data being received print(result.value!) if let dict = result.value as? Dictionary { if let train = dict["Train"] as? Dictionary { if let trainName = train["Name"] as? String{ print(trainName) } } } //connection close when tasks complete completed() } } } |
Python:
Python is a multi-pattern, all-purpose, paraphrased, high-level programming language. It allows coders to use various programming styles to build simple or complex programs, get expeditious outcomes and draft code as simple as they can.
1 2 3 4 5 6 7 |
import urllib # Python URL functions import urllib2 # Python URL functions url = "Enter http API here" # API URL req = urllib2.Request(url) response = urllib2.urlopen(req) output = response.read() # Get Response print output # Print Response |
Java:
Java is a multipurpose, high-level programming language developed by the Sun Microsystems. A lot of multimedia mobile phones ran with the help of Java only, back in the early 2000s.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import java.io.*; import java.net.URL; import java.net.URLConnection; import java.net.URLEncoder; public class SendSms{ public static void main(String[] args) { //Prepare Url URLConnection myURLConnection=null; URL myURL=null; BufferedReader reader=null; //Send SMS API String mainUrl="enter http API here"; try { //prepare connection myURL = new URL(mainUrl); myURLConnection = myURL.openConnection(); myURLConnection.connect(); reader= new BufferedReader(new InputStreamReader(myURLConnection.getInputStream())); //reading response String response; while ((response = reader.readLine()) != null) //print response System.out.println(response); //finally close connection reader.close(); } catch (IOException e) { e.printStackTrace(); } } } |
JQuery:
jQuery is a compact and quick JavaScript archive that can be applied to clarify event handling, HTML document traversing, Ajax interactions and animation for expeditious website development.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
$( document). ready (function () { //get-pnr-status is the id of the button or link. $('#pnrstatus' ).click (function(){ $. ajax ({ //1234567890 is the pnr number. replace with the variable. url: 'enter http API here', method: 'GET', crossDomain: true, dataType: 'json', success: function(data){ //You will need json2js for this alert. alert(JSON.stringify(data)); //result is the id of div where this response json will be displayed. $('#result').html(JSON.stringify(data)); }, error: function(data){ alert('ERROR'); } }); }); }); |
Node-JS:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
const https = require('https'); const URL = 'Enter http API here'; https.get(URL, (resp) => { let data = ''; // A chunk of data has been recieved. resp.on('data', (chunk) => { data += chunk; }); // The whole response has been received. Print out the result. resp.on('end', () => { console.log(JSON.parse(data)); }); }).on("error", (err) => { console.error("Error: " + err.message); }); |
Ruby:
1 2 3 4 5 6 7 8 9 |
require 'net/http' require 'json' #Rail API to be added here url = 'enter http API here' #Prepare and Execute the action uri = URI(url) response = Net::HTTP.get(uri) #Output print JSON.parse(response) |
Most of the API’s are not official: Official API’s will for only Big Brands.