In this tutorial, we show code examples in javascript. Of course, you can access the api in any other programming language.
Api Playground
You can play with the api at the Api Documentation. There is a demo api key at the top, that you can use for this purpose.
Authentication
You need to authorize with an free api key. Create one at the Api Dashboard. Store it safe in your application.
Method 1: Header Authentication
Pass the api key in the http request header named X-API-KEY
.
// Javascript example using lib node-fetch
fetch("https://antcheck.info/api/antcheck/shops", {
method: 'GET',
headers: {
'X-Api-Key': "YOUR-API-KEY"
},
})
Method 2: Query Authentication
Not recommended due to security risks. Only use if header authentication is not possible.
Pass the api key in the http query parameter named api_key
.
// Javascript example using lib node-fetch
fetch("https://antcheck.info/api/antcheck/shops?api_key=YOUR-API-KEY", {
method: 'GET'
})
Error handling
Error handling is done through http response codes. If the code is not 200, there is an problem.
200 OK = No error :)
401 Unauthorized = Problems with authentication :(
// Javascript example using lib node-fetch
fetch("https://antcheck.info/api/antcheck/shops", {
method: 'GET',
headers: {
'X-Api-Key': "YOUR-API-KEY"
},
})
.then(res => res.json()) // expecting a json response
.then(json => {
data = JSON.stringify(json);
console.log(data);
console.log("Success fetching AntCheck Shops Api.");
})
.catch(error => {
console.log("Error fetching AntCheck Shops Api: " + error);
})
Caching / Cron
Caching the API output is ideal for handling large data and reducing repeated API calls. Regular fetching through a cron job also ensures updated data without overwhelming the API or your system.
Cache API Output:
Store responses locally or in-memory (e.g., Redis) to avoid redundant API calls. Set expiration times on cached data based on how often it needs updating.
Cron Job for Regular Fetching:
Automate data fetching using cron jobs at set intervals (e.g., hourly). Store results in a database or file system. Useful when consistent updates are needed without real-time requirements. Helpful links: crontab.guru
// Example using lib node-schedule, 0 * * * * = @hourly
var cronjob1 = schedule.scheduleJob('0 * * * *', function() {
fetch("https://antcheck.info/api/antcheck/shops", {
method: 'GET',
headers: {
'X-Api-Key': "YOUR-API-KEY"
},
})
.then(res => res.json()) // expecting a json response
.then(json => {
json = JSON.stringify(json);
fs.writeFileSync("json/antcheck_shops.json", json); //Store results in a json file
console.log("Success fetching AntCheck Shops Api.");
})
.catch(error => {
console.log("Error fetching AntCheck Shops Api: " + error);
})
});