import { TrophyApiClient } from '@trophyso/node';
const trophy = new TrophyApiClient({
apiKey: 'YOUR_API_KEY'
});
const response = await trophy.admin.metrics.batchEvents([
{
key: 'words-written',
user: {
id: 'user-id',
email: 'user@example.com',
tz: 'Europe/London'
},
value: 750,
idempotencyKey: 'e4296e4b-8493-4bd1-9c30-5a1a9ac4d78f',
attributes: {
category: 'writing'
}
}
]);from trophy import TrophyApi
client = TrophyApi(api_key='YOUR_API_KEY')
response = client.admin.metrics.batch_events(
[
{
"key": "words-written",
"user": {
"id": "user-id",
"email": "user@example.com",
"tz": "Europe/London"
},
"value": 750,
"idempotencyKey": "e4296e4b-8493-4bd1-9c30-5a1a9ac4d78f",
"attributes": {
"category": "writing"
}
}
]
)import (
"context"
api "github.com/trophyso/trophy-go"
trophyclient "github.com/trophyso/trophy-go/client"
"github.com/trophyso/trophy-go/option"
)
client := trophyclient.NewClient(
option.WithApiKey("YOUR_API_KEY"),
)
response, err := client.Admin.Metrics.BatchEvents(
context.TODO(),
[]*api.BatchMetricEvent{
{
Key: "words-written",
User: &api.BatchMetricEventUser{Id: "user-id"},
Value: 750,
Attributes: map[string]string{
"category": "writing",
},
},
},
)curl --request POST \
--url https://admin.trophy.so/v1/metrics/events \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: <api-key>' \
--data '
[
{
"key": "words-written",
"user": {
"email": "user@example.com",
"tz": "Europe/London",
"id": "18",
"attributes": {
"department": "engineering",
"role": "developer"
}
},
"value": 750,
"idempotencyKey": "e4296e4b-8493-4bd1-9c30-5a1a9ac4d78f",
"attributes": {
"category": "writing",
"source": "mobile-app"
}
}
]
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://admin.trophy.so/v1/metrics/events",
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([
[
'key' => 'words-written',
'user' => [
'email' => 'user@example.com',
'tz' => 'Europe/London',
'id' => '18',
'attributes' => [
'department' => 'engineering',
'role' => 'developer'
]
],
'value' => 750,
'idempotencyKey' => 'e4296e4b-8493-4bd1-9c30-5a1a9ac4d78f',
'attributes' => [
'category' => 'writing',
'source' => 'mobile-app'
]
]
]),
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;
}HttpResponse<String> response = Unirest.post("https://admin.trophy.so/v1/metrics/events")
.header("X-API-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("[\n {\n \"key\": \"words-written\",\n \"user\": {\n \"email\": \"user@example.com\",\n \"tz\": \"Europe/London\",\n \"id\": \"18\",\n \"attributes\": {\n \"department\": \"engineering\",\n \"role\": \"developer\"\n }\n },\n \"value\": 750,\n \"idempotencyKey\": \"e4296e4b-8493-4bd1-9c30-5a1a9ac4d78f\",\n \"attributes\": {\n \"category\": \"writing\",\n \"source\": \"mobile-app\"\n }\n }\n]")
.asString();require 'uri'
require 'net/http'
url = URI("https://admin.trophy.so/v1/metrics/events")
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 {\n \"key\": \"words-written\",\n \"user\": {\n \"email\": \"user@example.com\",\n \"tz\": \"Europe/London\",\n \"id\": \"18\",\n \"attributes\": {\n \"department\": \"engineering\",\n \"role\": \"developer\"\n }\n },\n \"value\": 750,\n \"idempotencyKey\": \"e4296e4b-8493-4bd1-9c30-5a1a9ac4d78f\",\n \"attributes\": {\n \"category\": \"writing\",\n \"source\": \"mobile-app\"\n }\n }\n]"
response = http.request(request)
puts response.read_body{
"accepted": 1
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}Submit a batch of metric events
Submit up to 1,000 metric events for asynchronous processing.
import { TrophyApiClient } from '@trophyso/node';
const trophy = new TrophyApiClient({
apiKey: 'YOUR_API_KEY'
});
const response = await trophy.admin.metrics.batchEvents([
{
key: 'words-written',
user: {
id: 'user-id',
email: 'user@example.com',
tz: 'Europe/London'
},
value: 750,
idempotencyKey: 'e4296e4b-8493-4bd1-9c30-5a1a9ac4d78f',
attributes: {
category: 'writing'
}
}
]);from trophy import TrophyApi
client = TrophyApi(api_key='YOUR_API_KEY')
response = client.admin.metrics.batch_events(
[
{
"key": "words-written",
"user": {
"id": "user-id",
"email": "user@example.com",
"tz": "Europe/London"
},
"value": 750,
"idempotencyKey": "e4296e4b-8493-4bd1-9c30-5a1a9ac4d78f",
"attributes": {
"category": "writing"
}
}
]
)import (
"context"
api "github.com/trophyso/trophy-go"
trophyclient "github.com/trophyso/trophy-go/client"
"github.com/trophyso/trophy-go/option"
)
client := trophyclient.NewClient(
option.WithApiKey("YOUR_API_KEY"),
)
response, err := client.Admin.Metrics.BatchEvents(
context.TODO(),
[]*api.BatchMetricEvent{
{
Key: "words-written",
User: &api.BatchMetricEventUser{Id: "user-id"},
Value: 750,
Attributes: map[string]string{
"category": "writing",
},
},
},
)curl --request POST \
--url https://admin.trophy.so/v1/metrics/events \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: <api-key>' \
--data '
[
{
"key": "words-written",
"user": {
"email": "user@example.com",
"tz": "Europe/London",
"id": "18",
"attributes": {
"department": "engineering",
"role": "developer"
}
},
"value": 750,
"idempotencyKey": "e4296e4b-8493-4bd1-9c30-5a1a9ac4d78f",
"attributes": {
"category": "writing",
"source": "mobile-app"
}
}
]
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://admin.trophy.so/v1/metrics/events",
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([
[
'key' => 'words-written',
'user' => [
'email' => 'user@example.com',
'tz' => 'Europe/London',
'id' => '18',
'attributes' => [
'department' => 'engineering',
'role' => 'developer'
]
],
'value' => 750,
'idempotencyKey' => 'e4296e4b-8493-4bd1-9c30-5a1a9ac4d78f',
'attributes' => [
'category' => 'writing',
'source' => 'mobile-app'
]
]
]),
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;
}HttpResponse<String> response = Unirest.post("https://admin.trophy.so/v1/metrics/events")
.header("X-API-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("[\n {\n \"key\": \"words-written\",\n \"user\": {\n \"email\": \"user@example.com\",\n \"tz\": \"Europe/London\",\n \"id\": \"18\",\n \"attributes\": {\n \"department\": \"engineering\",\n \"role\": \"developer\"\n }\n },\n \"value\": 750,\n \"idempotencyKey\": \"e4296e4b-8493-4bd1-9c30-5a1a9ac4d78f\",\n \"attributes\": {\n \"category\": \"writing\",\n \"source\": \"mobile-app\"\n }\n }\n]")
.asString();require 'uri'
require 'net/http'
url = URI("https://admin.trophy.so/v1/metrics/events")
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 {\n \"key\": \"words-written\",\n \"user\": {\n \"email\": \"user@example.com\",\n \"tz\": \"Europe/London\",\n \"id\": \"18\",\n \"attributes\": {\n \"department\": \"engineering\",\n \"role\": \"developer\"\n }\n },\n \"value\": 750,\n \"idempotencyKey\": \"e4296e4b-8493-4bd1-9c30-5a1a9ac4d78f\",\n \"attributes\": {\n \"category\": \"writing\",\n \"source\": \"mobile-app\"\n }\n }\n]"
response = http.request(request)
puts response.read_body{
"accepted": 1
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}Authorizations
Headers
The tenant identifier for multi-tenant organisations. Required when the organisation has multi-tenancy enabled. Pass your own internal customer ID for the tenant. Ignored for single-tenant organisations.
Body
1 - 1000 elementsUnique reference of the metric as set when created.
"words-written"
The user that triggered the event.
Show child attributes
Show child attributes
The value to add to the user's current total for the given metric.
750
Event attributes as key-value pairs. Keys must match existing event attributes set up in the Trophy dashboard.
Show child attributes
Show child attributes
{
"category": "writing",
"source": "mobile-app"
}
Optional idempotency key for this event. When provided, the event is ignored if another event with the same idempotency key has already been processed.
"e4296e4b-8493-4bd1-9c30-5a1a9ac4d78f"
Response
Events accepted into the processing queue
Response returned when a batch of metric events is accepted.
The number of events accepted into the processing queue.
1
Was this page helpful?