Count Unread Notifications
curl --request GET \
--url https://api.sublay.io/v8/:projectId/app-notifications/unread-count \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.sublay.io/v8/:projectId/app-notifications/unread-count"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.sublay.io/v8/:projectId/app-notifications/unread-count', 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/app-notifications/unread-count",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.sublay.io/v8/:projectId/app-notifications/unread-count"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.sublay.io/v8/:projectId/app-notifications/unread-count")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.sublay.io/v8/:projectId/app-notifications/unread-count")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"count": 123
}App Notification Endpoints
Count Unread Notifications
Get the number of unread app notifications for the authenticated user
Count Unread Notifications
curl --request GET \
--url https://api.sublay.io/v8/:projectId/app-notifications/unread-count \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.sublay.io/v8/:projectId/app-notifications/unread-count"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.sublay.io/v8/:projectId/app-notifications/unread-count', 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/app-notifications/unread-count",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.sublay.io/v8/:projectId/app-notifications/unread-count"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.sublay.io/v8/:projectId/app-notifications/unread-count")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.sublay.io/v8/:projectId/app-notifications/unread-count")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"count": 123
}Returns the total number of unread app notifications for the currently authenticated user. Use this to populate notification badge counts in your UI.
This endpoint requires an authenticated user. Include a valid
Authorization: Bearer <accessToken> header, or use a service key and name the user in actingUserId.Query Parameters
string
Service key only, and required with one: the user this request acts as. Their unread notifications are counted. A user token always acts as its own user and must not send it (
400 app-notification/acting-user-not-allowed).Response
Returns HTTP200:
number
The number of unread app notifications.
{ "count": 7 }
Error Responses
Missing token — 401
Missing token — 401
No
Authorization header was sent. The body is text/plain, not JSON:Unauthorized
Expired or invalid token — 403
Expired or invalid token — 403
The header was sent but the token failed verification. Refresh the access
token and retry. The body is
text/plain, not JSON:Forbidden
Missing User — 400
Missing User — 400
A service key sent no
actingUserId.{
"error": "A service key must send actingUserId: the user this request acts as.",
"code": "app-notification/missing-user-id"
}
Acting User Not Allowed — 400
Acting User Not Allowed — 400
A user token sent
actingUserId, even naming its own user. Only a service key names the user it acts as; a user token always acts as its own user.{
"error": "actingUserId is only accepted with a service key. A user's own token always acts as that user.",
"code": "app-notification/acting-user-not-allowed"
}
User Not Found — 404
User Not Found — 404
Returned when a service key names an
actingUserId that isn’t a user in this project.{ "error": "No user with this actingUserId exists in this project.", "code": "app-notification/user-not-found" }
Unsupported Parameter — 400
Unsupported Parameter — 400
The request sent With a user token, or with no credentials:
userId. On this route the user a service key acts as is actingUserId.With a service key:{
"error": "`userId` was renamed to `actingUserId`: send the user this service key acts as in `actingUserId`.",
"code": "app-notification/unsupported-param",
"param": "userId"
}
{
"error": "`userId` isn't accepted here: a user's own token always acts as that user.",
"code": "app-notification/unsupported-param",
"param": "userId"
}
See Also
useAppNotificationshook — exposesunreadCountdirectly- Fetch Notifications

