Update: this tutorial uses the v7 endpoint. The current version uses /api/v9/rechargeplans, so check the v9 documentation before you copy the sample code.
Introduction
A recharge plans API is essential if your website or app offers online recharge. It is also known as a browse plan API or a mobile operator plan offer finder API. datayuge’s Recharge Plans API is updated daily, and its free tier lets you add recharge plans to your website. If you need a fully white-labelled solution with technical assistance, see the paid plans.
Step 1: Get your recharge plans API key
The browse plan API accepts requests to a secure server, authenticated with an API key passed in the URL. Register for a free key, or contact the datayuge team for a premium key.
Step 2: Call the API
With your key, you can integrate the API into a web or mobile app. A request looks like this:
https://api.datayuge.com/v7/rechargeplans/?apikey=YOUR_API_KEY&operator_id=Airtel&circle_id=DelhiReplace YOUR_API_KEY with your own key.
Step 3: Display the plans
The sample below shows mobile plans on a web page using basic HTML and PHP. Adapt it as you need; comments in the code explain each part.
First, create plans.css with the following styles for the page:
@import url('https://fonts.googleapis.com/css?family=Open+Sans:400,600,700');
@import url('https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css');
@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');
*, *:before, *:after {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html, body {
height: 100vh;
}
body {
font: 14px/1 'Open Sans', sans-serif;
color: #555;
background: #eee;
}
h1 {
padding: 50px 0;
font-weight: 400;
text-align: center;
}
p {
margin: 0 0 20px;
line-height: 1.5;
}
main {
min-width: 320px;
max-width: 800px;
padding: 50px;
margin: 0 auto;
background: #fff;
}
section {
display: none;
padding: 20px 0 0;
border-top: 1px solid #ddd;
}
input {
display: none;
}
label {
display: inline-block;
margin: 0 0 -1px;
padding: 15px 25px;
font-weight: 600;
text-align: center;
color: #bbb;
border: 1px solid transparent;
}
label:before {
font-family: fontawesome;
font-weight: normal;
margin-right: 10px;
}
label:hover {
color: #888;
cursor: pointer;
}
input:checked + label {
color: #555;
border: 1px solid #ddd;
border-top: 2px solid orange;
border-bottom: 1px solid #fff;
}
#tab1:checked ~ #content1,
#tab2:checked ~ #content2,
#tab3:checked ~ #content3,
#tab4:checked ~ #content4,
#tab5:checked ~ #content5,
#tab6:checked ~ #content6,
#tab7:checked ~ #content7,
#tab8:checked ~ #content8,
#tab9:checked ~ #content9,
#tab10:checked ~ #content10,
#tab11:checked ~ #content11 {
display: block;
}
@media screen and (max-width: 650px) {
label {
font-size: 0;
}
label:before {
margin: 0;
font-size: 18px;
}
}
@media screen and (max-width: 400px) {
label {
padding: 15px;
}
}
table {
border-collapse: collapse;
width: 100%;
}
th, td {
text-align: left;
padding: 8px;
}
tr:nth-child(even){background-color: #f2f2f2}Then create plans.php with the following code:
<html>
<head>
<link rel="stylesheet" href="plans.css">
</head>
<?php
/** datayuge Recharge Plans API
* The sample code for implementing the mobile recharge plans API or browse plans API in php & html
* The developer has to get the api key from datayuge before implementing. The used key is an dummy key.
* Author : [email protected]
**/
$operator_id = !isset($_GET['operator']) ? 'Airtel' : $_GET['operator'];
$circle_id = !isset($_GET['circle']) ? 'Kerala' : $_GET['circle'];
//Make the actual request to the server
$api = json_decode(file_get_contents("http://api.datayuge.com/v7/rechargeplans/?apikey=YOUR_API_KEY&operator_id=$operator_id&circle_id=$circle_id"))->data;
?>
<h1>datayuge Recharge Plans for <?php echo "$operator_id - $circle_id"?></h1>
<main>
<input id="tab1" type="radio" name="tabs" checked>
<label for="tab1">Top Up</label>
<input id="tab2" type="radio" name="tabs">
<label for="tab2">Full Talktime</label>
<input id="tab3" type="radio" name="tabs">
<label for="tab3">4G/3G Data</label>
<input id="tab4" type="radio" name="tabs">
<label for="tab4">2G Data</label>
<input id="tab5" type="radio" name="tabs">
<label for="tab5">SMS</label>
<input id="tab6" type="radio" name="tabs">
<label for="tab6">Local</label>
<input id="tab7" type="radio" name="tabs">
<label for="tab7">STD</label>
<input id="tab8" type="radio" name="tabs">
<label for="tab8">Others</label>
<input id="tab9" type="radio" name="tabs">
<label for="tab9">Plan/Combo</label>
<input id="tab10" type="radio" name="tabs">
<label for="tab10">Night</label>
<input id="tab11" type="radio" name="tabs">
<label for="tab11">Roaming</label>
<section id="content1">
<table>
<tr>
<th>Talktime</th>
<th>Validity</th>
<th>Description</th>
<th>Price</th>
</tr>
<?php
foreach ($api as $key => $data) {
if ($data->recharge_type == "Top up") { ?>
<tr>
<td> <?php echo !isset($data->recharge_talktime) ? '0' : $data->recharge_talktime ?> </td>
<td> <?php echo $data->recharge_validity ?> </td>
<td> <?php echo $data->recharge_long_desc ?></td>
<td> <button type="button" class="btn btn-primary"><?php echo "Rs. " .$data->recharge_amount ?></button></td>
</tr>
<?php }} ?>
</table>
</section>
<section id="content2">
<table>
<tr>
<th>Talktime</th>
<th>Validity</th>
<th>Description</th>
<th>Price</th>
</tr>
<?php
foreach ($api as $key => $data) {
if ($data->recharge_type == "Full Talktime") { ?>
<tr>
<td> <?php echo !isset($data->recharge_talktime) ? '0' : $data->recharge_talktime ?> </td>
<td> <?php echo $data->recharge_validity ?> </td>
<td> <?php echo $data->recharge_long_desc ?></td>
<td> <button type="button" class="btn btn-primary"><?php echo "Rs. " .$data->recharge_amount ?></button></td>
</tr>
<?php }} ?>
</table>
</section>
<section id="content3">
<table>
<tr>
<th>Talktime</th>
<th>Validity</th>
<th>Description</th>
<th>Price</th>
</tr>
<?php
foreach ($api as $key => $data) {
if ($data->recharge_type == "4G Data" || $data->recharge_type == "3G Data") { ?>
<tr>
<td> <?php echo !isset($data->recharge_talktime) ? '0' : $data->recharge_talktime ?> </td>
<td> <?php echo $data->recharge_validity ?> </td>
<td> <?php echo $data->recharge_long_desc ?></td>
<td> <button type="button" class="btn btn-primary"><?php echo "Rs. " .$data->recharge_amount ?></button></td>
</tr>
<?php }} ?>
</table>
</section>
<section id="content4">
<table>
<tr>
<th>Talktime</th>
<th>Validity</th>
<th>Description</th>
<th>Price</th>
</tr>
<?php
foreach ($api as $key => $data) {
if ($data->recharge_type == "2G Data") { ?>
<tr>
<td> <?php echo !isset($data->recharge_talktime) ? '0' : $data->recharge_talktime ?> </td>
<td> <?php echo $data->recharge_validity ?> </td>
<td> <?php echo $data->recharge_long_desc ?></td>
<td> <button type="button" class="btn btn-primary"><?php echo "Rs. " .$data->recharge_amount ?></button></td>
</tr>
<?php }} ?>
</table>
</section>
<section id="content5">
<table>
<tr>
<th>Talktime</th>
<th>Validity</th>
<th>Description</th>
<th>Price</th>
</tr>
<?php
foreach ($api as $key => $data) {
if ($data->recharge_type == "SMS") { ?>
<tr>
<td> <?php echo !isset($data->recharge_talktime) ? '0' : $data->recharge_talktime ?> </td>
<td> <?php echo $data->recharge_validity ?> </td>
<td> <?php echo $data->recharge_long_desc ?></td>
<td> <button type="button" class="btn btn-primary"><?php echo "Rs. " .$data->recharge_amount ?></button></td>
</tr>
<?php }} ?>
</table>
</section>
<section id="content6">
<table>
<tr>
<th>Talktime</th>
<th>Validity</th>
<th>Description</th>
<th>Price</th>
</tr>
<?php
foreach ($api as $key => $data) {
if ($data->recharge_type == "Local") { ?>
<tr>
<td> <?php echo !isset($data->recharge_talktime) ? '0' : $data->recharge_talktime ?> </td>
<td> <?php echo $data->recharge_validity ?> </td>
<td> <?php echo $data->recharge_long_desc ?></td>
<td> <button type="button" class="btn btn-primary"><?php echo "Rs. " .$data->recharge_amount ?></button></td>
</tr>
<?php }} ?>
</table>
</section>
<section id="content7">
<table>
<tr>
<th>Takltime</th>
<th>Validity</th>
<th>Description</th>
<th>Price</th>
</tr>
<?php
foreach ($api as $key => $data) {
if ($data->recharge_type == "STD") { ?>
<tr>
<td> <?php echo !isset($data->recharge_talktime) ? '0' : $data->recharge_talktime ?> </td>
<td> <?php echo $data->recharge_validity ?> </td>
<td> <?php echo $data->recharge_long_desc ?></td>
<td> <button type="button" class="btn btn-primary"><?php echo "Rs. " .$data->recharge_amount ?></button></td>
</tr>
<?php }} ?>
</table>
</section>
<section id="content8">
<table>
<tr>
<th>Talktime</th>
<th>Validity</th>
<th>Description</th>
<th>Price</th>
</tr>
<?php
foreach ($api as $key => $data) {
if ($data->recharge_type == "Other" || $data->recharge_type == "ISD") { ?>
<tr>
<td> <?php echo !isset($data->recharge_talktime) ? '0' : $data->recharge_talktime ?> </td>
<td> <?php echo $data->recharge_validity ?> </td>
<td> <?php echo $data->recharge_long_desc ?></td>
<td> <button type="button" class="btn btn-primary"><?php echo "Rs. " .$data->recharge_amount ?></button></td>
</tr>
<?php }} ?>
</table>
</section>
<section id="content9">
<table>
<tr>
<th>Talktime</th>
<th>Validity</th>
<th>Description</th>
<th>Price</th>
</tr>
<?php
foreach ($api as $key => $data) {
if ($data->recharge_type == "Plan") { ?>
<tr>
<td> <?php echo !isset($data->recharge_talktime) ? '0' : $data->recharge_talktime ?> </td>
<td> <?php echo $data->recharge_validity ?> </td>
<td> <?php echo $data->recharge_long_desc ?></td>
<td> <button type="button" class="btn btn-primary"><?php echo "Rs. " .$data->recharge_amount ?></button></td>
</tr>
<?php }} ?>
</table>
</section>
<section id="content10">
<table>
<tr>
<th>Talktime</th>
<th>Validity</th>
<th>Description</th>
<th>Price</th>
</tr>
<?php
foreach ($api as $key => $data) {
if ($data->recharge_type == "Night") { ?>
<tr>
<td> <?php echo !isset($data->recharge_talktime) ? '0' : $data->recharge_talktime ?> </td>
<td> <?php echo $data->recharge_validity ?> </td>
<td> <?php echo $data->recharge_long_desc ?></td>
<td> <button type="button" class="btn btn-primary"><?php echo "Rs. " .$data->recharge_amount ?></button></td>
</tr>
<?php }} ?>
</table>
</section>
<section id="content11">
<table>
<tr>
<th>Talktime</th>
<th>Validity</th>
<th>Description</th>
<th>Price</th>
</tr>
<?php
foreach ($api as $key => $data) {
if ($data->recharge_type == "Roaming") { ?>
<tr>
<td> <?php echo !isset($data->recharge_talktime) ? '0' : $data->recharge_talktime ?> </td>
<td> <?php echo $data->recharge_validity ?> </td>
<td> <?php echo $data->recharge_long_desc ?></td>
<td> <button type="button" class="btn btn-primary"><?php echo "Rs. " .$data->recharge_amount ?></button></td>
</tr>
<?php }} ?>
</table>
</section>
</main>
</html>The result looks like this:

You have now implemented the plans API. datayuge also provides a DTH Recharge Plans API. Read more about the browse plans API, or use the MNP Lookup API to find the operator and circle of ported numbers.