Code Examples
Ready-to-use code for common operations in cURL, PHP, Python, and Node.js. All examples include error handling and use environment variables for API keys.
Before you start: All examples assume your API key is stored in an environment variable called TEMPCLOCK_API_KEY. Set it with:
export TEMPCLOCK_API_KEY="tc_live_a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2"
List All Active Workers
Fetch all active workers with pagination support. Uses GET /workers.php.
curl -X GET \
"https://tempclock.com/api/v1/workers.php?active=1&limit=50&offset=0" \
-H "Authorization: Bearer $TEMPCLOCK_API_KEY" \
-H "Content-Type: application/json"
<?php
$api_key = getenv('TEMPCLOCK_API_KEY');
$base_url = 'https://tempclock.com/api/v1';
$params = [
'active' => 1,
'limit' => 50,
'offset' => 0,
];
$url = $base_url . '/workers.php?' . http_build_query($params);
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $api_key,
'Content-Type: application/json',
],
]);
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$data = json_decode($response, true);
if ($status !== 200) {
echo "Error {$status}: " . $data['message'] . "\n";
exit(1);
}
foreach ($data['data'] as $worker) {
printf("[%d] %s %s — %s\n",
$worker['id'],
$worker['first_name'],
$worker['last_name'],
$worker['location_name']
);
}
echo "Total: " . $data['pagination']['total'] . " workers\n";
import os
import requests
API_KEY = os.environ["TEMPCLOCK_API_KEY"]
BASE_URL = "https://tempclock.com/api/v1"
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
}
params = {
"active": 1,
"limit": 50,
"offset": 0,
}
response = requests.get(
f"{BASE_URL}/workers.php",
headers=headers,
params=params,
)
if response.status_code != 200:
error = response.json()
print(f"Error {error['status']}: {error['message']}")
exit(1)
data = response.json()
for worker in data["data"]:
print(f"[{worker['id']}] {worker['first_name']} {worker['last_name']} — {worker['location_name']}")
print(f"\nTotal: {data['pagination']['total']} workers")
const API_KEY = process.env.TEMPCLOCK_API_KEY;
const BASE_URL = "https://tempclock.com/api/v1";
async function listActiveWorkers() {
const params = new URLSearchParams({
active: "1",
limit: "50",
offset: "0",
});
const response = await fetch(
`${BASE_URL}/workers.php?${params}`,
{
headers: {
"Authorization": `Bearer ${API_KEY}`,
"Content-Type": "application/json",
},
}
);
const data = await response.json();
if (!response.ok) {
console.error(`Error ${data.status}: ${data.message}`);
process.exit(1);
}
data.data.forEach(worker => {
console.log(`[${worker.id}] ${worker.first_name} ${worker.last_name} — ${worker.location_name}`);
});
console.log(`\nTotal: ${data.pagination.total} workers`);
}
listActiveWorkers();
Get Timesheets for a Date Range
Pull timesheet data for a specific week, handling pagination to fetch all results. Uses GET /timesheets.php.
# Fetch timesheets for the first week of March 2026
curl -X GET \
"https://tempclock.com/api/v1/timesheets.php?date_from=2026-03-01&date_to=2026-03-07&limit=100" \
-H "Authorization: Bearer $TEMPCLOCK_API_KEY"
<?php
$api_key = getenv('TEMPCLOCK_API_KEY');
$base_url = 'https://tempclock.com/api/v1';
// Fetch all timesheets for a date range, handling pagination
function getAllTimesheets(string $from, string $to): array {
global $api_key, $base_url;
$all_entries = [];
$offset = 0;
$limit = 100;
do {
$url = $base_url . '/timesheets.php?' . http_build_query([
'date_from' => $from,
'date_to' => $to,
'limit' => $limit,
'offset' => $offset,
]);
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $api_key],
]);
$result = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status !== 200) {
throw new Exception("API error: " . $result['message']);
}
$all_entries = array_merge($all_entries, $result['data']);
$offset += $limit;
} while ($result['pagination']['has_more']);
return $all_entries;
}
$entries = getAllTimesheets('2026-03-01', '2026-03-07');
echo "Fetched " . count($entries) . " timesheet entries\n";
import os
import requests
API_KEY = os.environ["TEMPCLOCK_API_KEY"]
BASE_URL = "https://tempclock.com/api/v1"
HEADERS = {"Authorization": f"Bearer {API_KEY}"}
def get_all_timesheets(date_from: str, date_to: str) -> list:
"""Fetch all timesheets for a date range, handling pagination."""
all_entries = []
offset = 0
limit = 100
while True:
resp = requests.get(
f"{BASE_URL}/timesheets.php",
headers=HEADERS,
params={
"date_from": date_from,
"date_to": date_to,
"limit": limit,
"offset": offset,
},
)
resp.raise_for_status()
data = resp.json()
all_entries.extend(data["data"])
if not data["pagination"]["has_more"]:
break
offset += limit
return all_entries
entries = get_all_timesheets("2026-03-01", "2026-03-07")
print(f"Fetched {len(entries)} timesheet entries")
for entry in entries:
print(f" {entry['date']} | {entry['worker_name']} | {entry['hours_worked']}h")
const API_KEY = process.env.TEMPCLOCK_API_KEY;
const BASE_URL = "https://tempclock.com/api/v1";
async function getAllTimesheets(dateFrom, dateTo) {
const allEntries = [];
let offset = 0;
const limit = 100;
while (true) {
const params = new URLSearchParams({
date_from: dateFrom,
date_to: dateTo,
limit: String(limit),
offset: String(offset),
});
const resp = await fetch(`${BASE_URL}/timesheets.php?${params}`, {
headers: { "Authorization": `Bearer ${API_KEY}` },
});
if (!resp.ok) {
const err = await resp.json();
throw new Error(`API Error ${err.status}: ${err.message}`);
}
const data = await resp.json();
allEntries.push(...data.data);
if (!data.pagination.has_more) break;
offset += limit;
}
return allEntries;
}
(async () => {
const entries = await getAllTimesheets("2026-03-01", "2026-03-07");
console.log(`Fetched ${entries.length} entries`);
entries.forEach(e => console.log(` ${e.date} | ${e.worker_name} | ${e.hours_worked}h`));
})();
Clock In a Worker
Clock a worker in at a specific location, with error handling for the 409 conflict case. Uses POST /clock.php.
curl -X POST \
"https://tempclock.com/api/v1/clock.php" \
-H "Authorization: Bearer $TEMPCLOCK_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"worker_id": 142,
"action": "in",
"location_id": 3,
"notes": "Clocked in via API"
}'
<?php
$api_key = getenv('TEMPCLOCK_API_KEY');
$base_url = 'https://tempclock.com/api/v1';
$payload = json_encode([
'worker_id' => 142,
'action' => 'in',
'location_id' => 3,
'notes' => 'Clocked in via API',
]);
$ch = curl_init($base_url . '/clock.php');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $api_key,
'Content-Type: application/json',
],
]);
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$data = json_decode($response, true);
if ($status === 201) {
echo "Success: " . $data['message'] . "\n";
echo "Entry ID: " . $data['data']['id'] . "\n";
} elseif ($status === 409) {
echo "Conflict: " . $data['message'] . "\n";
// Worker is already clocked in — handle gracefully
} else {
echo "Error {$status}: " . $data['message'] . "\n";
}
import os
import requests
API_KEY = os.environ["TEMPCLOCK_API_KEY"]
BASE_URL = "https://tempclock.com/api/v1"
payload = {
"worker_id": 142,
"action": "in",
"location_id": 3,
"notes": "Clocked in via API",
}
response = requests.post(
f"{BASE_URL}/clock.php",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
},
json=payload,
)
data = response.json()
if response.status_code == 201:
print(f"Success: {data['message']}")
print(f"Entry ID: {data['data']['id']}")
elif response.status_code == 409:
print(f"Conflict: {data['message']}")
# Worker already clocked in — handle gracefully
else:
print(f"Error {data['status']}: {data['message']}")
const API_KEY = process.env.TEMPCLOCK_API_KEY;
const BASE_URL = "https://tempclock.com/api/v1";
async function clockInWorker(workerId, locationId, notes) {
const response = await fetch(`${BASE_URL}/clock.php`, {
method: "POST",
headers: {
"Authorization": `Bearer ${API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
worker_id: workerId,
action: "in",
location_id: locationId,
notes,
}),
});
const data = await response.json();
if (response.status === 201) {
console.log(`Success: ${data.message}`);
console.log(`Entry ID: ${data.data.id}`);
return data.data;
} else if (response.status === 409) {
console.warn(`Conflict: ${data.message}`);
// Worker already clocked in — handle gracefully
return null;
} else {
throw new Error(`Error ${data.status}: ${data.message}`);
}
}
clockInWorker(142, 3, "Clocked in via API");
Create a Shift
Schedule a new shift for a worker. Uses POST /shifts.php.
curl -X POST \
"https://tempclock.com/api/v1/shifts.php" \
-H "Authorization: Bearer $TEMPCLOCK_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"worker_id": 142,
"shift_date": "2026-03-15",
"start_time": "08:00",
"end_time": "16:00",
"location_id": 3,
"notes": "Saturday overtime"
}'
<?php
$api_key = getenv('TEMPCLOCK_API_KEY');
$base_url = 'https://tempclock.com/api/v1';
$shift = json_encode([
'worker_id' => 142,
'shift_date' => '2026-03-15',
'start_time' => '08:00',
'end_time' => '16:00',
'location_id' => 3,
'notes' => 'Saturday overtime',
]);
$ch = curl_init($base_url . '/shifts.php');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $shift,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $api_key,
'Content-Type: application/json',
],
]);
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$data = json_decode($response, true);
if ($status === 201) {
echo "Shift created: " . $data['message'] . "\n";
echo "Shift ID: " . $data['data']['id'] . "\n";
} else {
echo "Error {$status}: " . $data['message'] . "\n";
}
import os
import requests
API_KEY = os.environ["TEMPCLOCK_API_KEY"]
BASE_URL = "https://tempclock.com/api/v1"
shift_data = {
"worker_id": 142,
"shift_date": "2026-03-15",
"start_time": "08:00",
"end_time": "16:00",
"location_id": 3,
"notes": "Saturday overtime",
}
response = requests.post(
f"{BASE_URL}/shifts.php",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
},
json=shift_data,
)
data = response.json()
if response.status_code == 201:
print(f"Shift created: {data['message']}")
print(f"Shift ID: {data['data']['id']}")
print(f" Worker: {data['data']['worker_name']}")
print(f" Date: {data['data']['shift_date']}")
print(f" Time: {data['data']['start_time']} — {data['data']['end_time']}")
else:
print(f"Error {data['status']}: {data['message']}")
const API_KEY = process.env.TEMPCLOCK_API_KEY;
const BASE_URL = "https://tempclock.com/api/v1";
async function createShift(shiftData) {
const response = await fetch(`${BASE_URL}/shifts.php`, {
method: "POST",
headers: {
"Authorization": `Bearer ${API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify(shiftData),
});
const data = await response.json();
if (response.status === 201) {
console.log(`Shift created: ${data.message}`);
console.log(` ID: ${data.data.id}`);
console.log(` Worker: ${data.data.worker_name}`);
console.log(` Date: ${data.data.shift_date}`);
console.log(` Time: ${data.data.start_time} — ${data.data.end_time}`);
return data.data;
} else {
throw new Error(`Error ${data.status}: ${data.message}`);
}
}
createShift({
worker_id: 142,
shift_date: "2026-03-15",
start_time: "08:00",
end_time: "16:00",
location_id: 3,
notes: "Saturday overtime",
});