Increment a group counter
curl --request POST \
--url https://api.scrip.dev/v1/groups/{id}/state/counters/{key}/increment \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <api-key>' \
--data '
{
"delta": "5",
"reset_after": "720h"
}
'import requests
url = "https://api.scrip.dev/v1/groups/{id}/state/counters/{key}/increment"
payload = {
"delta": "5",
"reset_after": "720h"
}
headers = {
"X-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({delta: '5', reset_after: '720h'})
};
fetch('https://api.scrip.dev/v1/groups/{id}/state/counters/{key}/increment', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.scrip.dev/v1/groups/{id}/state/counters/{key}/increment",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'delta' => '5',
'reset_after' => '720h'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.scrip.dev/v1/groups/{id}/state/counters/{key}/increment"
payload := strings.NewReader("{\n \"delta\": \"5\",\n \"reset_after\": \"720h\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.scrip.dev/v1/groups/{id}/state/counters/{key}/increment")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"delta\": \"5\",\n \"reset_after\": \"720h\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.scrip.dev/v1/groups/{id}/state/counters/{key}/increment")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"delta\": \"5\",\n \"reset_after\": \"720h\"\n}"
response = http.request(request)
puts response.read_body{
"key": "purchases",
"last_reset_at": "2024-01-15T10:30:00Z",
"reset_after": "720h",
"value": "42"
}{
"code": "bad_request",
"details": {
"expected": "uuid",
"field": "asset_id",
"fields": [
{
"expected": "<unknown>",
"field": "amount",
"message": "This field is required",
"reason": "required",
"received": "-10.00"
}
],
"reason": "invalid",
"received": "not-a-uuid"
},
"message": "Invalid request parameters"
}{
"code": "unauthorized",
"details": {
"expected": "uuid",
"field": "asset_id",
"fields": [
{
"expected": "<unknown>",
"field": "amount",
"message": "This field is required",
"reason": "required",
"received": "-10.00"
}
],
"reason": "invalid",
"received": "not-a-uuid"
},
"message": "Missing or invalid credentials"
}{
"code": "not_found",
"details": {
"expected": "uuid",
"field": "asset_id",
"fields": [
{
"expected": "<unknown>",
"field": "amount",
"message": "This field is required",
"reason": "required",
"received": "-10.00"
}
],
"reason": "invalid",
"received": "not-a-uuid"
},
"message": "Resource not found"
}{
"code": "unsupported_media_type",
"details": {
"expected": "uuid",
"field": "asset_id",
"fields": [
{
"expected": "<unknown>",
"field": "amount",
"message": "This field is required",
"reason": "required",
"received": "-10.00"
}
],
"reason": "invalid",
"received": "not-a-uuid"
},
"message": "Content-Type must be application/json"
}{
"code": "internal_error",
"message": "An internal error occurred"
}State
Increment a group counter
Atomically add delta to a counter (negative deltas decrement). If the counter does not exist, it is created with delta as its value.
POST
/
v1
/
groups
/
{id}
/
state
/
counters
/
{key}
/
increment
Increment a group counter
curl --request POST \
--url https://api.scrip.dev/v1/groups/{id}/state/counters/{key}/increment \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <api-key>' \
--data '
{
"delta": "5",
"reset_after": "720h"
}
'import requests
url = "https://api.scrip.dev/v1/groups/{id}/state/counters/{key}/increment"
payload = {
"delta": "5",
"reset_after": "720h"
}
headers = {
"X-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({delta: '5', reset_after: '720h'})
};
fetch('https://api.scrip.dev/v1/groups/{id}/state/counters/{key}/increment', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.scrip.dev/v1/groups/{id}/state/counters/{key}/increment",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'delta' => '5',
'reset_after' => '720h'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.scrip.dev/v1/groups/{id}/state/counters/{key}/increment"
payload := strings.NewReader("{\n \"delta\": \"5\",\n \"reset_after\": \"720h\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.scrip.dev/v1/groups/{id}/state/counters/{key}/increment")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"delta\": \"5\",\n \"reset_after\": \"720h\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.scrip.dev/v1/groups/{id}/state/counters/{key}/increment")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"delta\": \"5\",\n \"reset_after\": \"720h\"\n}"
response = http.request(request)
puts response.read_body{
"key": "purchases",
"last_reset_at": "2024-01-15T10:30:00Z",
"reset_after": "720h",
"value": "42"
}{
"code": "bad_request",
"details": {
"expected": "uuid",
"field": "asset_id",
"fields": [
{
"expected": "<unknown>",
"field": "amount",
"message": "This field is required",
"reason": "required",
"received": "-10.00"
}
],
"reason": "invalid",
"received": "not-a-uuid"
},
"message": "Invalid request parameters"
}{
"code": "unauthorized",
"details": {
"expected": "uuid",
"field": "asset_id",
"fields": [
{
"expected": "<unknown>",
"field": "amount",
"message": "This field is required",
"reason": "required",
"received": "-10.00"
}
],
"reason": "invalid",
"received": "not-a-uuid"
},
"message": "Missing or invalid credentials"
}{
"code": "not_found",
"details": {
"expected": "uuid",
"field": "asset_id",
"fields": [
{
"expected": "<unknown>",
"field": "amount",
"message": "This field is required",
"reason": "required",
"received": "-10.00"
}
],
"reason": "invalid",
"received": "not-a-uuid"
},
"message": "Resource not found"
}{
"code": "unsupported_media_type",
"details": {
"expected": "uuid",
"field": "asset_id",
"fields": [
{
"expected": "<unknown>",
"field": "amount",
"message": "This field is required",
"reason": "required",
"received": "-10.00"
}
],
"reason": "invalid",
"received": "not-a-uuid"
},
"message": "Content-Type must be application/json"
}{
"code": "internal_error",
"message": "An internal error occurred"
}Atomically adds
delta to a counter. Concurrent increments never lose updates, unlike set counter, which replaces the value with last-write-wins semantics. Negative deltas decrement.
If the counter does not exist, it is created with delta as its value.
For usage patterns and examples, see the State Management guide.
Authorizations
ApiKeyAuthBearerAuth
API key passed in the X-API-Key header.
Body
application/json
Delta to add and optional reset_after
⌘I