How to Use PAJ Data API
1. Before you can use API key
authentication, you will first need to generate an API key
here (Register is needed)
2. Pass the API key with each
request: Once you have an API key, you will need to pass it with each
request to the API using the headers or query parameters. Use the 'api-key'
header for passing the key.
Below are few example on how you can call PAJ API from different set of
language.
const headers = new Headers();
headers.append('api-key', 'YOUR_API_KEY');
fetch('https://dataapi.paj.com.my/api/v1/busroute', { headers: headers })
.then(response => response.json())
.then(data => {
console.log(data);
})
.catch(error => {
console.error('Error:', error);
});
$.ajax({
type: 'GET',
url: 'https://dataapi.paj.com.my/api/v1/busroute',
headers: { 'api-key': 'YOUR_API_KEY' },
success: function(data) {
console.log(data);
},
error: function(xhr, status, error) {
console.error('Error:', error);
}
});
$apiKey = 'YOUR_API_KEY';
$options = array(
'http' => array(
'method' => 'GET',
'header' => "api-key: $apiKey\r\n"
)
);
$context = stream_context_create($options);
$result = file_get_contents('https://dataapi.paj.com.my/api/v1/busroute', false, $context);
if ($result === FALSE) { /* Handle error */ }
var_dump($result);
api_key = 'YOUR_API_KEY'
headers = {'api-key': api_key}
response = requests.get('https://dataapi.paj.com.my/api/v1/busroute', headers=headers)
if response.status_code == 200:
print(response.json())
else:
print('Error:', response.status_code)
const https = require('https');
const apiKey = 'YOUR_API_KEY';
const options = {
hostname: 'https://dataapi.paj.com.my/api/v1',
path: '/busroute',
headers: { 'api-key': apiKey }
};
const req = https.request(options, (res) => {
res.on('data', (d) => {
process.stdout.write(d);
});
});
req.on('error', (error) => {
console.error(error);
});
req.end();
var client = new HttpClient();
client.DefaultRequestHeaders.Add("api-key", "YOUR_API_KEY");
var response = await client.GetAsync("https://dataapi.paj.com.my/api/v1/busroute");
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);
}
else
{
Console.WriteLine("Error: " + response.StatusCode);
}
Rate Limit
In order to protect our system from abuse by unetichal users, there is a very
generous limit on our API generation.
6 request per minute
An error of Rate Limit Reach
will appear if you pass this
threshold. A cooldown of another 1 minute
will be applied when you
need to call
next API
Response
You will get a valid response if
correct paramenter with valid api-key is given. All response provided will be in
JSON formating
// https://dataapi.paj.com.my/api/v1/bus-list/YOW HOE
{
"status": "success",
"data": [
"BKN6733",
"FB9311",
"VDU5595"
]
}
// https://dataapi.paj.com.my/api/v1/bus-list/YOW HOE
{
"status": "error",
"message": "Invalid API Key"
}
Error Handling
In case you get an error message, below is description why it is happening
API Key Required
- Make sure you send
api-key header. The name of the header must be 'api-key'.
Invalid API Key
- There is no such api-key
exist in data api database.
Invalid parameter or endpoint
- Make sure
that your url endpoint is correct or make sure that url parameter is
correct
Rate limit reach
- Just wait another 1
minute cooldown before call next API
Empty Valid Response
In the case of no data available for particular reponse. The system will simply reply with an empty array. In example below, since there is no such operator name of "SKYNET", hence system will simply response with empty array.
// https://dataapi.paj.com.my/api/v1/bus-list/SKYNET
{
"status": "success",
"data": []
}