EXAMPLE #14
PHP
Bash
Update an existing event
Edit any field on an existing event.
14-update-event.php
#!/usr/bin/env php
<?php
/**
* Example: Update an existing event
*
* PUT /api/events/{event-uuid}
*
* Only the fields you send are updated; omitted fields remain unchanged.
* Updatable fields: timestamp, number, source, key, value
*
* Usage:
* php 14-update-event.php <event-uuid>
*/
$baseUrl = 'https://www.spaceplace.app';
$dataStreamId = 'YOUR-DATASTREAM-UUID-HERE';
$tokenValue = 'YOUR-TOKEN-VALUE-HERE';
$eventId = $argv[1] ?? 'YOUR-EVENT-UUID-HERE';
$updates = [
'number' => 999,
'value' => 'corrected-value',
];
$ch = curl_init("{$baseUrl}/api/events/{$eventId}");
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Accept: application/json',
"X-DataStream-ID: {$dataStreamId}",
"X-Token: {$tokenValue}",
],
CURLOPT_POSTFIELDS => json_encode($updates),
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$body = json_decode($response, true);
if ($httpCode === 200) {
$e = $body['event'];
echo "Event updated: {$e['id']}\n";
echo " Number: {$e['number']}\n";
echo " Value: {$e['value']}\n";
} elseif ($httpCode === 404) {
echo "Event not found.\n";
} else {
echo "Failed (HTTP {$httpCode}):\n";
print_r($body);
}
14-update-event.sh
#!/usr/bin/env bash
#
# Example: Update an existing event
#
# PUT /api/events/{event-uuid}
#
# Only the fields you send are updated; omitted fields remain unchanged.
# Updatable fields: timestamp, number, source, key, value
#
# Usage:
# bash 14-update-event.sh <event-uuid>
BASE_URL="https://www.spaceplace.app"
DATASTREAM_ID="YOUR-DATASTREAM-UUID-HERE"
TOKEN_VALUE="YOUR-TOKEN-VALUE-HERE"
EVENT_ID="${1:-YOUR-EVENT-UUID-HERE}"
response=$(curl -s -w "\n%{http_code}" \
-X PUT \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "X-DataStream-ID: ${DATASTREAM_ID}" \
-H "X-Token: ${TOKEN_VALUE}" \
-d '{
"number": 999,
"value": "corrected-value"
}' \
"${BASE_URL}/api/events/${EVENT_ID}")
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | sed '$d')
if [ "$http_code" = "200" ]; then
echo "Event updated: $(echo "$body" | jq -r '.event.id')"
echo " Number: $(echo "$body" | jq -r '.event.number')"
echo " Value: $(echo "$body" | jq -r '.event.value')"
elif [ "$http_code" = "404" ]; then
echo "Event not found."
else
echo "Failed (HTTP ${http_code}):"
echo "$body" | jq .
fi