Skip to main content

Script API Reference

This document provides detailed information about the Script API endpoints, which are designed for automated scripts and system maintenance operations.

Authentication​

All endpoints in the Script API require:

  • Valid API key in the request header
  • SCRIPT role

Base URL​

/script

Endpoints​

Invalidate Cache​

Invalidates a specific cache entry in Redis based on the provided key.

POST /script/invalidate-cache

Request Body​

{
"key": "string" // The cache key to invalidate
}

Response​

{
"status": "success"
}

Error Responses​

  • 400 Bad Request: When the key is missing or invalid
  • 401 Unauthorized: When the API key is invalid or missing
  • 403 Forbidden: When the request doesn't have the required SCRIPT role

Usage Examples​

cURL Example​

curl -X POST \
'http://api.example.com/script/invalidate-cache' \
-H 'Content-Type: application/json' \
-H 'X-API-KEY: your-api-key' \
-d '{
"key": "user:profile:12345"
}'

JavaScript Example​

const response = await fetch('http://api.example.com/script/invalidate-cache', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-KEY': 'your-api-key',
},
body: JSON.stringify({
key: 'user:profile:12345',
}),
});

const data = await response.json();
console.log(data); // { status: "success" }

Security Considerations​

  1. API Key Protection: Keep your API key secure and do not expose it in client-side code
  2. Role Assignment: Ensure that only trusted services have the SCRIPT role
  3. Key Patterns: Be cautious about the cache keys you invalidate, as they may affect system performance

Rate Limiting​

These endpoints have strict rate limits to prevent abuse:

  • 60 requests per minute per API key
  • Exceeding this limit will result in 429 Too Many Requests responses

Best Practices​

  1. Targeted Invalidation: Only invalidate specific cache entries rather than using wildcard patterns
  2. Monitoring: Monitor cache invalidation operations as they can impact system performance
  3. Documentation: Keep a record of which scripts are invalidating which cache keys
  4. Scheduling: Schedule cache invalidation operations during periods of low system load when possible