Skip to main content

Health Check

Monitor the status and availability of the Sakneen API using the health check endpoint.

Health Check Endpoint

The health check endpoint allows you to verify that the API is running and accessible.

Endpoint Details

  • Method: GET
  • Path: /external/apis/v1.0/healthz
  • Authentication: Requires API key

Request Example

curl --location 'https://your-domain/external/apis/v1.0/healthz' \
--header 'api-key: your-api-key-here'

Local Development:

curl --location 'http://localhost:8080/external/apis/v1.0/healthz' \
--header 'api-key: your-api-key-here'

Response

A successful health check returns an HTTP 200 status code, indicating the API is healthy and operational.

Success Response (200 OK):

API is healthy

Error Response (401 Unauthorized):

{
"message": "Unauthorized",
"statusCode": 401
}

Integration Examples

JavaScript/Node.js

const checkApiHealth = async () => {
const domain = process.env.SAKNEEN_DOMAIN; // your assigned domain
const apiKey = process.env.SAKNEEN_API_KEY;

try {
const response = await fetch(`https://${domain}/external/apis/v1.0/healthz`, {
method: 'GET',
headers: {
'api-key': apiKey
}
});

if (response.ok) {
const message = await response.text();
console.log('API Health Status:', message);
return true;
} else {
console.error('API Health Check Failed:', response.status);
return false;
}
} catch (error) {
console.error('Health check error:', error);
return false;
}
};

// Usage
checkApiHealth().then(isHealthy => {
if (isHealthy) {
console.log('API is ready for use');
} else {
console.log('API is not available');
}
});

Python

import requests
import os

def check_api_health():
domain = os.getenv('SAKNEEN_DOMAIN') # your assigned domain
api_key = os.getenv('SAKNEEN_API_KEY')

headers = {
'api-key': api_key
}

try:
response = requests.get(
f'https://{domain}/external/apis/v1.0/healthz',
headers=headers
)

if response.status_code == 200:
print(f'API Health Status: {response.text}')
return True
else:
print(f'API Health Check Failed: {response.status_code}')
return False

except requests.exceptions.RequestException as e:
print(f'Health check error: {e}')
return False

# Usage
if check_api_health():
print('API is ready for use')
else:
print('API is not available')

PHP

<?php
function checkApiHealth() {
$domain = $_ENV['SAKNEEN_DOMAIN']; // your assigned domain
$apiKey = $_ENV['SAKNEEN_API_KEY'];

$headers = [
'api-key: ' . $apiKey
];

$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{$domain}/external/apis/v1.0/healthz",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $headers,
]);

$response = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);

if ($httpCode === 200) {
echo "API Health Status: $response\n";
return true;
} else {
echo "API Health Check Failed: $httpCode\n";
return false;
}
}

// Usage
if (checkApiHealth()) {
echo "API is ready for use\n";
} else {
echo "API is not available\n";
}
?>

Monitoring and Alerting

Automated Health Checks

You can set up automated health checks to monitor your API availability:

// Health check every 5 minutes
setInterval(async () => {
const isHealthy = await checkApiHealth();

if (!isHealthy) {
// Send alert to your monitoring system
console.error('ALERT: Sakneen API is not responding');
// You could send notifications, emails, etc.
}
}, 5 * 60 * 1000); // 5 minutes

Load Balancer Health Checks

If you're using a load balancer, configure it to use this endpoint for health checks:

# Example for AWS Application Load Balancer
healthcheck:
path: /external/apis/v1.0/healthz
interval: 30
timeout: 5
retries: 3
headers:
api-key: your-api-key-here

Best Practices

  1. Regular Monitoring: Implement regular health checks in your application
  2. Error Handling: Always handle health check failures gracefully
  3. Timeout Configuration: Set appropriate timeouts for health check requests
  4. Logging: Log health check results for monitoring and debugging
  5. Fallback Logic: Implement fallback mechanisms when health checks fail

Troubleshooting

Common Issues

401 Unauthorized

  • Verify your API key is correct
  • Ensure the API key is included in the request headers

Connection Timeout

  • Check your network connectivity
  • Verify the domain is correct
  • Ensure you're using the right protocol (http vs https)

503 Service Unavailable

  • The API might be temporarily down for maintenance
  • Contact support if the issue persists

Contact Support

If you're experiencing persistent health check failures:

  • Email: [email protected]
  • Include your domain and API key (first/last few characters only)
  • Provide error messages and timestamps
  • Describe your network setup if relevant