Cron Job API
ASP.NET Core Cron Job API for Shared Hosting Environments
API Endpoints
-
Execute Cron Job:
GET /api/cron/run-hourly-task -
Check Status:
GET /api/cron/status -
Health Check:
GET /api/cron/health
Authentication
API endpoints require authentication using one of these methods:
- Query String:
?key=your-secret-key - Header:
X-Cron-Key: your-secret-key
Header authentication is recommended for security.
Example Usage
Linux/Mac (curl):
curl -H "X-Cron-Key: CJ9x7mK2pL8nQ4vR6wE3tY1uI5oP0aS9dF7gH2jK6lM8nB4vC1xZ3qW5eR7tY9uI" "https://crontest.saducs.in/api/cron/run-hourly-task"
PowerShell:
# Option 1: Using hashtable
Invoke-RestMethod -Uri "https://crontest.saducs.in/api/cron/run-hourly-task" -Headers @{"X-Cron-Key"="CJ9x7mK2pL8nQ4vR6wE3tY1uI5oP0aS9dF7gH2jK6lM8nB4vC1xZ3qW5eR7tY9uI"}
# Option 2: Using variables (recommended)
$headers = @{"X-Cron-Key" = "CJ9x7mK2pL8nQ4vR6wE3tY1uI5oP0aS9dF7gH2jK6lM8nB4vC1xZ3qW5eR7tY9uI"}
Invoke-RestMethod -Uri "https://crontest.saducs.in/api/cron/run-hourly-task" -Headers $headers
Windows Command Prompt (curl):
curl -H "X-Cron-Key: CJ9x7mK2pL8nQ4vR6wE3tY1uI5oP0aS9dF7gH2jK6lM8nB4vC1xZ3qW5eR7tY9uI" "https://crontest.saducs.in/api/cron/run-hourly-task"
PHP:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://crontest.saducs.in/api/cron/run-hourly-task");
curl_setopt($ch, CURLOPT_HTTPHEADER, ["X-Cron-Key: CJ9x7mK2pL8nQ4vR6wE3tY1uI5oP0aS9dF7gH2jK6lM8nB4vC1xZ3qW5eR7tY9uI"]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
Database
The API logs each execution to the CronExecutionLogs table:
- SrNo: Auto-increment primary key
- CreatedAt: Execution timestamp
Features
- Duplicate execution prevention
- Configurable minimum intervals
- UTC/Local time support
- Comprehensive logging
- Health monitoring
- CORS enabled
Quick Test
Test the health endpoint (no authentication required): Check Health