cURL
Use cURL to test ingestion, automate a server-side script, or verify an API key before adding an SDK.
Send an event
Export the key in your shell rather than writing it into a script:
export TELEMETRY_API_KEY="YOUR_API_KEY"
curl --fail-with-body \
--request POST \
"https://api.telemetry.sh/log" \
--header "Authorization: ${TELEMETRY_API_KEY}" \
--header "Content-Type: application/json" \
--data '{
"table": "api_requests",
"data": {
"route_template": "/api/projects/:id",
"method": "GET",
"status_code": 200,
"latency_ms": 184
}
}'
Telemetry adds timestamp_utc to each event. Do not send API keys, authorization headers, cookies, raw request bodies, or other sensitive content as event fields.
Run a SQL query
curl --fail-with-body \
--request POST \
"https://api.telemetry.sh/query" \
--header "Authorization: ${TELEMETRY_API_KEY}" \
--header "Content-Type: application/json" \
--data @- <<'JSON'
{
"query": "SELECT route_template, COUNT(*) AS requests, ROUND(AVG(latency_ms), 0) AS avg_latency_ms FROM api_requests WHERE timestamp_utc >= now() - INTERVAL '24 hours' GROUP BY route_template ORDER BY requests DESC;"
}
JSON
Use a read-scoped key for query-only scripts and a write-scoped key for ingestion-only scripts.
Export a larger result asynchronously
curl --fail-with-body \
--request POST \
"https://api.telemetry.sh/query/async" \
--header "Authorization: ${TELEMETRY_API_KEY}" \
--header "Content-Type: application/json" \
--data @- <<'JSON'
{
"query": "SELECT * FROM api_requests WHERE timestamp_utc >= now() - INTERVAL '30 days' ORDER BY timestamp_utc DESC;",
"format": "parquet"
}
JSON
The response includes a status URL. Poll it with the same authorization header until the job completes, then download the result from the returned download URL.
See the Log API, Query API, and SQL recipe library for more examples.