EXAMPLE #04
PHP
Bash
Minimal event (all defaults)
The smallest valid body — every event field is optional.
04-send-event-minimal.php
#!/usr/bin/env php
<?php
/**
* Example: Send a minimal Event (all defaults)
*
* Demonstrates that every Event field is optional. The server will assign
* the current timestamp, number=0, and empty strings for source/key/value.
* This is useful for simple counter-style events where only the occurrence
* matters.
*
* Usage:
* php 04-send-event-minimal.php
*/
$baseUrl = 'https://www.spaceplace.app';
$dataStreamId = 'YOUR-DATASTREAM-UUID-HERE';
$tokenValue = 'YOUR-TOKEN-VALUE-HERE';
// Empty payload -- all fields use server defaults
$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(new stdClass()), // empty JSON object: {}
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$body = json_decode($response, true);
if ($httpCode === 201) {
echo "Minimal event created: {$body['event_id']} at {$body['timestamp']}\n";
} else {
echo "Failed (HTTP {$httpCode}):\n";
print_r($body);
exit(1);
}
04-send-event-minimal.sh
#!/usr/bin/env bash
#
# Example: Send a minimal Event (all defaults)
#
# Every Event field is optional. The server will assign the current
# timestamp, number=0, and empty strings for source/key/value.
# Useful for simple counter-style events.
#
# Usage:
# bash 04-send-event-minimal.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 '{}')
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | sed '$d')
if [ "$http_code" = "201" ]; then
echo "Minimal event created: $(echo "$body" | jq -r '.event_id') at $(echo "$body" | jq -r '.timestamp')"
else
echo "Failed (HTTP ${http_code}):"
echo "$body" | jq .
exit 1
fi