EXAMPLE #02
PHP
Bash
Send an event with a timestamp
Backdate or schedule an event with an explicit timestamp.
02-send-event-with-timestamp.php
#!/usr/bin/env php
<?php
/**
* Example: Send an Event with a specific timestamp
*
* Useful for backfilling historical data or when the event occurred at a
* known time different from "now".
*
* Usage:
* php 02-send-event-with-timestamp.php
*/
$baseUrl = 'https://www.spaceplace.app';
$dataStreamId = 'YOUR-DATASTREAM-UUID-HERE';
$tokenValue = 'YOUR-TOKEN-VALUE-HERE';
$event = [
'timestamp' => '2026-03-15 08:30:00', // specific past timestamp
'number' => 100,
'source' => 'historical-import',
'key' => 'sales-count',
'value' => '153',
];
$ch = curl_init("{$baseUrl}/api/events");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Accept: application/json',
"X-DataStream-ID: {$dataStreamId}",
"X-Token: {$tokenValue}",
],
CURLOPT_POSTFIELDS => json_encode($event),
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$body = json_decode($response, true);
if ($httpCode === 201) {
echo "Event created at {$body['timestamp']}\n";
echo " Event ID: {$body['event_id']}\n";
} else {
echo "Failed (HTTP {$httpCode}):\n";
print_r($body);
exit(1);
}
02-send-event-with-timestamp.sh
#!/usr/bin/env bash
#
# Example: Send an Event with a specific timestamp
#
# Useful for backfilling historical data or when the event occurred at a
# known time different from "now".
#
# Usage:
# bash 02-send-event-with-timestamp.sh
BASE_URL="https://www.spaceplace.app"
DATASTREAM_ID="YOUR-DATASTREAM-UUID-HERE"
TOKEN_VALUE="YOUR-TOKEN-VALUE-HERE"
response=$(curl -s -w "\n%{http_code}" \
-X POST "${BASE_URL}/api/events" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "X-DataStream-ID: ${DATASTREAM_ID}" \
-H "X-Token: ${TOKEN_VALUE}" \
-d '{
"timestamp": "2026-03-15 08:30:00",
"number": 100,
"source": "historical-import",
"key": "sales-count",
"value": "153"
}')
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | sed '$d')
if [ "$http_code" = "201" ]; then
echo "Event created at $(echo "$body" | jq -r '.timestamp')"
echo " Event ID: $(echo "$body" | jq -r '.event_id')"
else
echo "Failed (HTTP ${http_code}):"
echo "$body" | jq .
exit 1
fi