{"_id":"563a2dbd1846790d0089531b","editedParams":true,"category":{"_id":"563a2dbb1846790d0089530b","project":"54d4ecb5f6c48a0d00f0f041","pages":["563a2dbd1846790d00895318","563a2dbd1846790d00895319","563a2dbd1846790d0089531a","563a2dbd1846790d0089531b","563a2dbd1846790d0089531c","563a2dbd1846790d0089531d","563a2dbd1846790d0089531e"],"version":"563a2dba1846790d00895309","__v":1,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-02-06T16:37:55.318Z","from_sync":false,"order":3,"slug":"endpoints","title":"API Endpoints"},"project":"54d4ecb5f6c48a0d00f0f041","user":"54d4ec36f6c48a0d00f0f040","editedParams2":true,"version":{"_id":"563a2dba1846790d00895309","__v":3,"project":"54d4ecb5f6c48a0d00f0f041","createdAt":"2015-11-04T16:09:30.844Z","releaseDate":"2015-11-04T16:09:30.844Z","categories":["563a2dbb1846790d0089530a","563a2dbb1846790d0089530b","563a2dbb1846790d0089530c","56620e60f183880d004d3217","5702e5b8f2d6f336005e9025"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"No Mashape","version_clean":"1.1.0","version":"1.1"},"__v":1,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-04-07T00:23:23.810Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"examples":{"codes":[{"name":"Example Increment Payload","code":"{\n    \"amount\": 23,\n    \"async\": false\n}","language":"json"}]},"method":"post","results":{"codes":[{"status":201,"language":"json","code":"{\n  \"meta\": \n  {\n    \":::at:::self\": \n    {\n    \t\"href\": \"https://api.instacount.io/sharded_counters/123/shards/0/operations/27f19d74-c2b3-4235-8c14-6a28c9774c89\"\n  \t}\n\t},\n  \"id\": \"27f19d74-c2b3-4235-8c14-6a28c9774c89\",\n  \"type\": \"INCREMENT\",\n  \"amount\": 1,\n  \"created\": \"2015-04-07T00:30:23.574Z\",\n  \"shardIndex\": 0\n}","name":"OK"},{"code":"{\n  \"errors\": [\n    {\n      \"message\": \"What you requested does not exist.\",\n      \"developerMessage\": \"The resource you requests was not found!\",\n      \"moreInfo\": \"https://instacount.readme.io\"\n    }\n  ]\n}","language":"json","status":404},{"name":"Invalid Increment Amount","status":400,"language":"json","code":"{\n  \"errors\": [\n    {\n      \"message\": \"Counter increment amounts must be positive numbers!\",\n      \"developerMessage\": \"Counter increment amounts must be positive numbers!\",\n      \"moreInfo\": \"https://www.mashape.com/instacount/instacountapi/overview#wiki-errors\"\n    }\n  ]\n}"},{"status":401,"language":"json","code":"{\n  \"errors\": [\n    {\n      \"message\": \"You must be signed-in to access the information you requested.\",\n      \"developerMessage\": \"You must enable proper Instacount Authentication!  Invalid X-Instacount-API-Key Header!\",\n      \"moreInfo\": \"https://instacount.readme.io\"\n    }\n  ]\n}"}]},"settings":"","auth":"required","params":[{"_id":"55231031dbe3622300a324b6","ref":"","in":"path","required":true,"desc":"A unique name that identifies the counter.","default":"num-followers-123","type":"string","name":"name"},{"_id":"564fbc5566438d0d0026ee1c","ref":"","in":"body","required":false,"desc":"The amount to increment the counter.","default":"1","type":"string","name":"amount"},{"_id":"564fbc5566438d0d0026ee1b","ref":"","in":"body","required":false,"desc":"True if the increment operation should occur asynchronously, false if the increment should occur synchronously.","default":"false","type":"boolean","name":"async"}],"url":"/sharded_counters/:name/increments"},"isReference":false,"order":3,"body":"Incrementing a counter is as easy as making an HTTP *POST* to a named counter's **/increment** endpoint.  There are two supported methodologies for incrementing a counter: **synchronous** and **asynchronous**.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Asynchronous Counter Increment\"\n}\n[/block]\nAsynchronous counter increments are the fastest type of increment, but will result in an eventually consistent increment.  In other words, if Instacount accepts the request to increment, then you can reliably assume that the increment will be applied *eventually*, usually within a few seconds or less.\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Use Asynchronous If You Don't Want to Wait\",\n  \"body\": \"Asynchronous increment requests will return nearly instantly, but the actual counter increment will not be generally be applied for a few seconds.  In extremely rare cases, an async increment may take longer to apply.  If you receive an HTTP 202 response code from Instacount, your increment is guaranteed to be applied.\"\n}\n[/block]\n\nThe following is an example increment request payload to specify an asynchronous increment:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n    \\\"amount\\\": 1,\\n    \\\"async\\\": true\\n}\",\n      \"language\": \"json\",\n      \"name\": null\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"danger\",\n  \"title\": \"Increment Amounts Must be Positive Numbers\",\n  \"body\": \"Note that the **increment_amount** must be a positive number.  If you wish to decrement a counter, you must use the [decrements](decrement-counter) endpoint.\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Synchronous Counter Increment\"\n}\n[/block]\nSynchronous counter increments are a *slightly* slower type of increment, but will result in a strongly consistent increment.  In other words, if Instacount responds with a 201 Created response, then the increment can be considered to be applied and a request to get a counter will reflect the applied increment.\n\nThe following is an example increment request payload to specify an synchronous increment:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n    \\\"amount\\\": 1,\\n    \\\"async\\\": false\\n}\",\n      \"language\": \"json\",\n      \"name\": \"Synchronous Counter Increment\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"danger\",\n  \"body\": \"Note that the **increment_amount** must be a positive number.  If you wish to decrement a counter, you must use the [decrements](decrement-counter) endpoint.\",\n  \"title\": \"Increment Amounts Must be Positive Numbers\"\n}\n[/block]","excerpt":"Create and apply an increment for a counter","slug":"increment-counter","type":"endpoint","title":"Increment a Counter"}

postIncrement a Counter

Create and apply an increment for a counter

Definition

{{ api_url }}{{ page_api_url }}

Parameters

Path Params

name:
required
stringnum-followers-123
A unique name that identifies the counter.

Body Params

amount:
string1
The amount to increment the counter.
async:
booleanfalse
True if the increment operation should occur asynchronously, false if the increment should occur synchronously.

Examples


Result Format


Documentation

Incrementing a counter is as easy as making an HTTP *POST* to a named counter's **/increment** endpoint. There are two supported methodologies for incrementing a counter: **synchronous** and **asynchronous**. [block:api-header] { "type": "basic", "title": "Asynchronous Counter Increment" } [/block] Asynchronous counter increments are the fastest type of increment, but will result in an eventually consistent increment. In other words, if Instacount accepts the request to increment, then you can reliably assume that the increment will be applied *eventually*, usually within a few seconds or less. [block:callout] { "type": "info", "title": "Use Asynchronous If You Don't Want to Wait", "body": "Asynchronous increment requests will return nearly instantly, but the actual counter increment will not be generally be applied for a few seconds. In extremely rare cases, an async increment may take longer to apply. If you receive an HTTP 202 response code from Instacount, your increment is guaranteed to be applied." } [/block] The following is an example increment request payload to specify an asynchronous increment: [block:code] { "codes": [ { "code": "{\n \"amount\": 1,\n \"async\": true\n}", "language": "json", "name": null } ] } [/block] [block:callout] { "type": "danger", "title": "Increment Amounts Must be Positive Numbers", "body": "Note that the **increment_amount** must be a positive number. If you wish to decrement a counter, you must use the [decrements](decrement-counter) endpoint." } [/block] [block:api-header] { "type": "basic", "title": "Synchronous Counter Increment" } [/block] Synchronous counter increments are a *slightly* slower type of increment, but will result in a strongly consistent increment. In other words, if Instacount responds with a 201 Created response, then the increment can be considered to be applied and a request to get a counter will reflect the applied increment. The following is an example increment request payload to specify an synchronous increment: [block:code] { "codes": [ { "code": "{\n \"amount\": 1,\n \"async\": false\n}", "language": "json", "name": "Synchronous Counter Increment" } ] } [/block] [block:callout] { "type": "danger", "body": "Note that the **increment_amount** must be a positive number. If you wish to decrement a counter, you must use the [decrements](decrement-counter) endpoint.", "title": "Increment Amounts Must be Positive Numbers" } [/block]

User Information

Try It Out

post
{{ tryResults.results }}
Method{{ tryResults.method }}
Request Headers
{{ tryResults.requestHeaders }}
URL{{ tryResults.url }}
Request Data
{{ tryResults.data }}
Status
Response Headers
{{ tryResults.responseHeaders }}