Overview¶
URL¶
The HTTP API is available at: https://globalr.com/doc/api/
Attention
For security reasons, you should always send API requests using HTTPS.
Authentication¶
All requests require the following authentication parameter:
- api_key : An alphanumeric code that can be used to authenticate your API calls
Attention
If you want send test request you mast send param mode=test
.
Request Limits¶
Per minute you can send 128 request.
Simple request example in PHP¶
Lets for testing purposes create some global function, to test our requests.
Note
This function for quick testing, and must be improved in real environment. But it is used in this documentation everywhere .
<?php
function sendToGlobalR($params, $method = 'GET', $path = '/domain', $token = 'xXGsvO26ntTHTESTKEYSOICKu8nOvMzKKiwg', $serverUrl='https://globalr.com/api', $mode="test")
{
//lets create url to where we must send our requests
$url = $serverUrl.$path.'?';
//Bind in params our api token
$params['api_token'] = $token;
$params['mode'] = $mode;
//Initialize curl session
$ch = curl_init();
//check if method is get bind prams to url
if ($method == 'GET') {
$url .= http_build_query($params);
}
//set curl option for url
curl_setopt($ch, CURLOPT_URL, $url);
//check if request method is not GET or POST bind custom request type
if (strtoupper($method) != 'GET' AND strtoupper($method) != 'POST') {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($method));
}
//If method is not GET bind fields as post field
if ($method != 'GET') {
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_HTTPHEADER,["Accept: application/json"]);
}
//set param for return transfer(to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//get resault
$result = curl_exec($ch);
//close curl session
curl_close($ch);
return $result;
}
Lets try chek if domain available or not and get prices if available
$params = [];
$resault = sendToGlobalR($params, 'GET', '/domain/checkfreedomain.am', 'xXGsvO26ntTHTESTKEYSOICKu8nOvMzKKiwg');
Example responce
{
"domain": "checkfreedomain.am",
"massage": "This domain can be registered",
"available": true,
"whois": "%\n%AM TLD whois server #1\n%\n\nNo match\n\n",
"prices": [
{
"price": "16.80",
"year": "1"
},
{
"price": "33.60",
"year": "2"
},
{
"price": "50.40",
"year": "3"
},
{
"price": "67.20",
"year": "4"
},
{
"price": "84.00",
"year": "5"
}
]
}
Lets check domain is free or not
$domain = json_decode($resault);
if($domain->available){
echo "Domain Can be registered";
} else {
echo "Domain already registerd";
}
Final code
<?php
function sendToGlobalR($params, $method = 'GET', $path = '/domain', $token = 'xXGsvO26ntTHTESTKEYSOICKu8nOvMzKKiwg', $serverUrl='https://globalr.com/api')
{
//lets create url to where we must send our requests
$url = $serverUrl.$path.'?';
//Bind in params our api token
$params['api_token'] = $token;
//Initialize curl session
$ch = curl_init();
//check if method is get bind prams to url
if ($method == 'GET') {
$url .= http_build_query($params);
}
//set curl option for url
curl_setopt($ch, CURLOPT_URL, $url);
//check if request method is not GET or POST bind custom request type
if (strtoupper($method) != 'GET' AND strtoupper($method) != 'POST') {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($method));
}
//If method is not GET bind fields as post field
if ($method != 'GET') {
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Accept: application/json"]);
}
//set param for return transfer(to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//if we need headers this option required
//curl_setopt($ch, CURLINFO_HEADER_OUT, true);
//get resault
$resault = curl_exec($ch);
//And in this way we can get header information
//$Headerinfo = curl_getinfo($ch,CURLINFO_HEADER_OUT);
//Http status Code
//$httpStatus = curl_getinfo($ch,CURLINFO_HTTP_CODE);
//close curl session
curl_close($ch);
return $resault;
}
$params = [];
$resault = sendToGlobalR($params, 'GET', '/domain/checkfreedomain.am', 'xXGsvO26ntTHTESTKEYSOICKu8nOvMzKKiwg');
$domain = json_decode($resault);
if($domain->available){
echo "Domain Can be registered";
} else {
echo "Domain already registerd";
}