Counter API
The Counter API provides a integer counter service for your application. The counters are stored in our database and can be accessed via IDs unique to the provided API key.
For free users, counters are kept for 14 days.
For premium users, counters are retained indefinitely until it becomes inactive for 180 days, at which point it gets deleted.
From 5,189 users
Applications using this API
API Status
API Response Times
Average | P50 | P75 | P90 | P95 |
|---|---|---|---|---|
| 199ms | 237ms | 295ms | 694ms | 1058ms |
Didn't find what you were looking for? Suggest an improvement
/v1/counter GET
https://api.api-ninjas.com/v1/counter
Fetch and possibly update a counter.
Parameters
idrequiredID to specify the counter. Use a new
idto create a new counter.hitoptionalWhether to increase the count by 1. If used, must be set to
true.valueoptionalSet the count to a specific integer value. Setting the value to 0 resets the counter.
Headers
X-Api-KeyrequiredAPI Key associated with your account.
Response
A JSON object with the following fields or an error if the request is unsuccessful.
idThe counter ID.
valueThe current counter value.
Sample Request Live Demo!
Try our APIs in the API playground
Sign up for a free API key to get started — no credit card required.
https://api.api-ninjas.com/v1/counter?id=test_id&hit=trueHeaders
X-Api-KeyLog in or sign up to get your API KeySample Response
Code Examples
1
2
curl -X GET "https://api.api-ninjas.com/v1/counter?id=test_id&hit=true" \
-H "X-Api-Key: YOUR_API_KEY"If your programming language is not listed in the Code Example above, you can still make API calls by using a HTTP request library written in your programming language and following the above documentation.
Frequently Asked Questions
Can I use the Counter API for commercial purposes?
Yes, but you must have a premium subscription. Commercial use of the Counter API is not permitted on the free tier. See our pricing page to choose a plan that fits your needs.How do I get an API key and start using the Counter API?
Sign up for a free account to instantly get your API key, then pass it in theX-Api-Keyheader on every request. The documentation above includes ready-to-run examples in cURL, Python, JavaScript, Node.js, and more.What happens if I exceed my quota for the month?
Your API requests will simply be denied once you hit your monthly quota — you will never be charged more than the plan you signed up for. To increase your quota, you can upgrade your plan any time on our pricing page.What happens if a request to the Counter API fails?
The API responds with a standard HTTP status code and a JSON error message describing the problem. See our error codes reference for the full list of codes and how to resolve each one, or contact support if you need help.How do I create and increment a counter with the Counter API?
Pass a uniqueidto create a new counter, then includehitset totrueon each request to increase its count by 1; the response returns theidand currentvalue. Sign up for a free API key to get started.Can I set or reset a counter to a specific value?
Yes, include the optionalvalueparameter to set the counter to a specific integer, and setvalueto 0 to reset the counter. See the full parameter list on the Counter API documentation.How long are my counters retained?
For free users, counters are kept for 14 days, while premium users have counters retained indefinitely until they become inactive for 180 days, at which point they are deleted.Are counters shared across different API keys?
No, counters are stored in our database and accessed viaidvalues that are unique to your provided API key, so your counters are isolated to your account. Register to obtain your own key.