List account events and mark them seen
Short answer
This page has 2 commands: List or search account events (POST /v2/account/events/search) and Mark account event(s) as seen (POST /v2/account/events/seen). List all events triggered for account. Each call needs a bearer token and counts towards your hourly API limit. Below are the parameters, sample code in 9 languages and a sample answer.
After reading this you will know
- How to list account events and mark them seen
- Which parameters each of the 2 commands takes
- Sample code in 9 languages and a sample answer
Every command on this page needs a bearer token and counts towards your hourly limit.
List or search account events
Section titled “List or search account events”https://api.sirv.com/v2/account/events/search
List all events triggered for account.
Request body (JSON)
| Field | Type | Required | Example | Description |
|---|---|---|---|---|
module | string | No | fetching | Only events from this part of Sirv, for example fetching. |
type | string | No | Only events of this type. | |
filename | string | No | /REST API Examples/aurora.jpg | Only events about this file. |
level | string | No | error | One of: error, warn, info. |
seen | boolean | No | false | Filter seen/unseen events |
Example request
// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variableconst res = await fetch('https://api.sirv.com/v2/account/events/search', { method: 'POST', headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}`, 'content-type': 'application/json' }, body: JSON.stringify({ "module": "fetching" }),});console.log(res.status, await res.text());import requests
res = requests.post( 'https://api.sirv.com/v2/account/events/search', headers={'authorization': 'Bearer BEARER_TOKEN', 'content-type': 'application/json'}, json={ "module": "fetching" },)print(res.status_code, res.text)curl --request POST \ --url 'https://api.sirv.com/v2/account/events/search' \ --header 'authorization: Bearer BEARER_TOKEN' \ --header 'content-type: application/json' \ --data '{"module":"fetching"}'import java.net.URI;import java.net.http.HttpClient;import java.net.http.HttpRequest;import java.net.http.HttpResponse;
HttpClient client = HttpClient.newHttpClient();HttpRequest request = HttpRequest.newBuilder(URI.create("https://api.sirv.com/v2/account/events/search")) .header("authorization", "Bearer BEARER_TOKEN") .header("content-type", "application/json") .method("POST", HttpRequest.BodyPublishers.ofString(""" { "module": "fetching" } """)) .build();HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());System.out.println(response.statusCode() + " " + response.body());using System.Net.Http.Headers;
using var client = new HttpClient();var request = new HttpRequestMessage(new HttpMethod("POST"), "https://api.sirv.com/v2/account/events/search");request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "BEARER_TOKEN");request.Content = new StringContent("""{ "module": "fetching"}""", System.Text.Encoding.UTF8, "application/json");var response = await client.SendAsync(request);Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");<?php$ch = curl_init('https://api.sirv.com/v2/account/events/search');curl_setopt_array($ch, [ CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => ['authorization: Bearer BEARER_TOKEN', 'content-type: application/json'], CURLOPT_POSTFIELDS => json_encode([ 'module' => 'fetching' ]), CURLOPT_RETURNTRANSFER => true,]);echo curl_exec($ch);package main
import ( "fmt" "io" "net/http" "strings")
func main() { body := strings.NewReader(`{ "module": "fetching" }`) req, _ := http.NewRequest("POST", "https://api.sirv.com/v2/account/events/search", body) req.Header.Set("authorization", "Bearer BEARER_TOKEN") req.Header.Set("content-type", "application/json") res, err := http.DefaultClient.Do(req) if err != nil { panic(err) } defer res.Body.Close() out, _ := io.ReadAll(res.Body) fmt.Println(res.Status, string(out))}require 'net/http'
uri = URI('https://api.sirv.com/v2/account/events/search')req = Net::HTTP::Post.new(uri)req['authorization'] = 'Bearer BEARER_TOKEN'req['content-type'] = 'application/json'req.body = <<~'JSON' { "module": "fetching" }JSONres = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }puts res.code, res.bodyimport Foundation
var request = URLRequest(url: URL(string: "https://api.sirv.com/v2/account/events/search")!)request.httpMethod = "POST"request.setValue("Bearer BEARER_TOKEN", forHTTPHeaderField: "authorization")request.setValue("application/json", forHTTPHeaderField: "content-type")request.httpBody = #"""{ "module": "fetching"}"""#.data(using: .utf8)let (data, response) = try await URLSession.shared.data(for: request)print((response as! HTTPURLResponse).statusCode, String(decoding: data, as: UTF8.self))Example response
[ { "module": "fetching", "type": "http", "level": "error", "filename": "/REST API Examples/missing.jpg", "fetching": { "url": "https://demo.sirv.com/missing.jpg", "statusCode": 404, "maxFilesize": 2097152, "contentLength": "4140", "error": "Request not successful: expected status code 200 but got 404" }, "initiator": { "type": "api", "remoteAddr": "176.105.166.4", "date": "2020-07-18T11:31:32.229Z" }, "notify": true, "_seen": false, "_submitted": "2020-07-18T11:31:32.612Z", "_accountId": "sdulth0oi0t9zxpxqtxwkwvgipjgv6ud", "_id": "8fbb11a7dd77f7f64337e581ccbce2d62fc7cda0" }]Mark account event(s) as seen
Section titled “Mark account event(s) as seen”https://api.sirv.com/v2/account/events/seen
Add seen flag for specified account event(s).
Example request
// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variableconst res = await fetch('https://api.sirv.com/v2/account/events/seen', { method: 'POST', headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}`, 'content-type': 'application/json' }, body: JSON.stringify([ "f1f5d68ef232e5d27d10f28bcef836efbb7cdeba", "199cf48046964f8567fe49e22107c4c5d27271e7" ]),});console.log(res.status, await res.text());import requests
res = requests.post( 'https://api.sirv.com/v2/account/events/seen', headers={'authorization': 'Bearer BEARER_TOKEN', 'content-type': 'application/json'}, json=[ "f1f5d68ef232e5d27d10f28bcef836efbb7cdeba", "199cf48046964f8567fe49e22107c4c5d27271e7" ],)print(res.status_code, res.text)curl --request POST \ --url 'https://api.sirv.com/v2/account/events/seen' \ --header 'authorization: Bearer BEARER_TOKEN' \ --header 'content-type: application/json' \ --data '["f1f5d68ef232e5d27d10f28bcef836efbb7cdeba","199cf48046964f8567fe49e22107c4c5d27271e7"]'import java.net.URI;import java.net.http.HttpClient;import java.net.http.HttpRequest;import java.net.http.HttpResponse;
HttpClient client = HttpClient.newHttpClient();HttpRequest request = HttpRequest.newBuilder(URI.create("https://api.sirv.com/v2/account/events/seen")) .header("authorization", "Bearer BEARER_TOKEN") .header("content-type", "application/json") .method("POST", HttpRequest.BodyPublishers.ofString(""" [ "f1f5d68ef232e5d27d10f28bcef836efbb7cdeba", "199cf48046964f8567fe49e22107c4c5d27271e7" ] """)) .build();HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());System.out.println(response.statusCode() + " " + response.body());using System.Net.Http.Headers;
using var client = new HttpClient();var request = new HttpRequestMessage(new HttpMethod("POST"), "https://api.sirv.com/v2/account/events/seen");request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "BEARER_TOKEN");request.Content = new StringContent("""[ "f1f5d68ef232e5d27d10f28bcef836efbb7cdeba", "199cf48046964f8567fe49e22107c4c5d27271e7"]""", System.Text.Encoding.UTF8, "application/json");var response = await client.SendAsync(request);Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");<?php$ch = curl_init('https://api.sirv.com/v2/account/events/seen');curl_setopt_array($ch, [ CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => ['authorization: Bearer BEARER_TOKEN', 'content-type: application/json'], CURLOPT_POSTFIELDS => json_encode([ 'f1f5d68ef232e5d27d10f28bcef836efbb7cdeba', '199cf48046964f8567fe49e22107c4c5d27271e7' ]), CURLOPT_RETURNTRANSFER => true,]);echo curl_exec($ch);package main
import ( "fmt" "io" "net/http" "strings")
func main() { body := strings.NewReader(`[ "f1f5d68ef232e5d27d10f28bcef836efbb7cdeba", "199cf48046964f8567fe49e22107c4c5d27271e7" ]`) req, _ := http.NewRequest("POST", "https://api.sirv.com/v2/account/events/seen", body) req.Header.Set("authorization", "Bearer BEARER_TOKEN") req.Header.Set("content-type", "application/json") res, err := http.DefaultClient.Do(req) if err != nil { panic(err) } defer res.Body.Close() out, _ := io.ReadAll(res.Body) fmt.Println(res.Status, string(out))}require 'net/http'
uri = URI('https://api.sirv.com/v2/account/events/seen')req = Net::HTTP::Post.new(uri)req['authorization'] = 'Bearer BEARER_TOKEN'req['content-type'] = 'application/json'req.body = <<~'JSON' [ "f1f5d68ef232e5d27d10f28bcef836efbb7cdeba", "199cf48046964f8567fe49e22107c4c5d27271e7" ]JSONres = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }puts res.code, res.bodyimport Foundation
var request = URLRequest(url: URL(string: "https://api.sirv.com/v2/account/events/seen")!)request.httpMethod = "POST"request.setValue("Bearer BEARER_TOKEN", forHTTPHeaderField: "authorization")request.setValue("application/json", forHTTPHeaderField: "content-type")request.httpBody = #"""[ "f1f5d68ef232e5d27d10f28bcef836efbb7cdeba", "199cf48046964f8567fe49e22107c4c5d27271e7"]"""#.data(using: .utf8)let (data, response) = try await URLSession.shared.data(for: request)print((response as! HTTPURLResponse).statusCode, String(decoding: data, as: UTF8.self))Response
HTTP 200 with an empty body when the command succeeds.