Increment Entity Views
curl --request POST \
--url https://api.sublay.io/v8/:projectId/entities/:entityId/increment-views \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"count": 123
}'import requests
url = "https://api.sublay.io/v8/:projectId/entities/:entityId/increment-views"
payload = { "count": 123 }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({count: 123})
};
fetch('https://api.sublay.io/v8/:projectId/entities/:entityId/increment-views', 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.sublay.io/v8/:projectId/entities/:entityId/increment-views",
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([
'count' => 123
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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.sublay.io/v8/:projectId/entities/:entityId/increment-views"
payload := strings.NewReader("{\n \"count\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.sublay.io/v8/:projectId/entities/:entityId/increment-views")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"count\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.sublay.io/v8/:projectId/entities/:entityId/increment-views")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"count\": 123\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"views": 123
}Entity Endpoints
Increment Entity Views
Add to an entity’s view count
Increment Entity Views
curl --request POST \
--url https://api.sublay.io/v8/:projectId/entities/:entityId/increment-views \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"count": 123
}'import requests
url = "https://api.sublay.io/v8/:projectId/entities/:entityId/increment-views"
payload = { "count": 123 }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({count: 123})
};
fetch('https://api.sublay.io/v8/:projectId/entities/:entityId/increment-views', 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.sublay.io/v8/:projectId/entities/:entityId/increment-views",
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([
'count' => 123
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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.sublay.io/v8/:projectId/entities/:entityId/increment-views"
payload := strings.NewReader("{\n \"count\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.sublay.io/v8/:projectId/entities/:entityId/increment-views")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"count\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.sublay.io/v8/:projectId/entities/:entityId/increment-views")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"count\": 123\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"views": 123
}Increments an entity’s
views counter and returns the updated entity.
This endpoint requires a service key and cannot be called with an end-user token. It always acts as your app: sending
actingUserId returns 400 entity/unsupported-param. Count views from your own backend rather than from the client, so a browser cannot inflate the number.Path Parameters
Body Parameters
How much to add to the counter: a JSON integer of at least
1. Defaults to 1 (an empty body or no body increments by one). A string such as "3", a fraction or 0 returns 400 entity/invalid-body. Pass a batch total to record views your backend has buffered rather than calling the endpoint once per view.Example body
{ "count": 25 }
Response
Returns the full updated Entity, withviews reflecting the increment.
Error Responses
Invalid Parameters — 400
Invalid Parameters — 400
{ "error": "Invalid entity id: expected a UUID.", "code": "entity/invalid-params", "param": "entityId" }
Invalid Count — 400
Invalid Count — 400
Returned when
count is not a JSON integer of at least 1 (a string, a fraction or 0).{ "error": "count: Count must be a positive integer", "code": "entity/invalid-body" }
Wrong Location — 400
Wrong Location — 400
Returned when
count is sent in the query string. On this endpoint it goes in the request body.{ "error": "`count` goes in the request body on this endpoint.", "code": "entity/wrong-location", "param": "count" }
Elevated Auth Required — 403
Elevated Auth Required — 403
{
"error": "Service key required.",
"code": "auth/elevated-auth-required"
}
Entity Not Found — 404
Entity Not Found — 404
{ "error": "Entity not found.", "code": "entity/not-found" }
Server Error — 500
Server Error — 500
{
"error": "An error occurred while updating entity views.",
"code": "entity/server-error"
}
Unsupported Parameter — 400
Unsupported Parameter — 400
The request sent
actingUserId. This endpoint always acts as the app, so no caller may name a user.{ "error": "`actingUserId` isn't accepted here: this endpoint always acts as the app.", "code": "entity/unsupported-param", "param": "actingUserId" }

