# Cron Expression API (`caulleonard/cron-api`) Actor

Validate cron expressions and compute next run times via a simple HTTP API.

- **URL**: https://apify.com/caulleonard/cron-api.md
- **Developed by:** [Fatih Şahinbaş](https://apify.com/caulleonard) (community)
- **Categories:** Developer tools
- **Stats:** 2 total users, 1 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.00 / 1,000 api calls

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## Cron Expression API — Validate, Describe & Calculate Next Run Times

A fast, no-nonsense HTTP API for working with **cron expressions**. Validate crontab syntax, calculate the **next run times**, look up previous runs, and turn any cron schedule into a plain-English description — all through simple GET requests.

Stop guessing whether `*/15 9-17 * * 1-5` is correct or when it fires next. This **cron parser API** answers instantly, with full timezone support.

### What it does

- ✅ **Validate cron expressions** — catch bad fields, out-of-range values, and wrong field counts with clear per-field error messages.
- ⏭️ **Next run times** — compute the upcoming N execution times for any cron schedule, in any IANA timezone.
- ⏮️ **Previous run times** — look back at when a schedule last fired.
- 💬 **Human-readable descriptions** — convert `0 17 * * 1` into "At 17:00, only on Monday".
- 🧩 **One-call parse** — validation, description, and next runs in a single request.

### Who it's for

Developers building schedulers, CI/CD pipelines, job queues, dashboards, and admin panels who need to validate crontab input or preview when a cron job will run — without shipping a cron library into every service. Perfect for form validation, "next run" previews in UIs, and documentation tooling.

### Supported syntax

- Standard **5-field** cron: `minute hour day-of-month month day-of-week`
- **6-field** cron with seconds: `second minute hour day-of-month month day-of-week`
- **Macros**: `@yearly` `@annually` `@monthly` `@weekly` `@daily` `@hourly` `@midnight`
- **Ranges, lists, steps**: `1-5`, `1,3,5`, `*/15`, `9-17`
- **Names**: `sun`, `mon`, `jan`, `feb`, ...
- **Extensions**: `L` (last day), `W` (nearest weekday), `#` (nth weekday) — e.g. `0 0 * * 1#2` = second Monday.

### Endpoints

All endpoints are **GET** and return JSON.

| Endpoint | Purpose | Key params |
|----------|---------|------------|
| `/validate` | Check if an expression is valid | `expr` |
| `/next` | Next N run times | `expr`, `count`, `tz`, `base` |
| `/prev` | Previous N run times | `expr`, `count`, `tz`, `base` |
| `/describe` | Plain-English description | `expr` |
| `/parse` | Validate + describe + next runs in one call | `expr`, `count`, `tz`, `base` |

**Parameters**

- `expr` *(required)* — the cron expression, e.g. `*/15 9-17 * * 1-5`
- `count` — how many run times to return (default `5`, max `100`)
- `tz` — IANA timezone (default `UTC`), e.g. `Europe/Istanbul`, `America/New_York`
- `base` — ISO 8601 datetime to calculate from (default: now)

### Example

Request:

```
GET /parse?expr=0 9 * * 1-5&count=3&tz=Europe/Istanbul
```

Response:

```json
{
  "valid": true,
  "normalized": "0 9 * * 1-5",
  "fields": 5,
  "description": "At 09:00, Monday through Friday",
  "tz": "Europe/Istanbul",
  "next_runs": [
    "2026-01-05T09:00:00+03:00",
    "2026-01-06T09:00:00+03:00",
    "2026-01-07T09:00:00+03:00"
  ],
  "warning": null
}
```

Invalid input returns a helpful error:

```
GET /validate?expr=60 * * * *
```

```json
{
  "valid": false,
  "normalized": "60 * * * *",
  "fields": null,
  "errors": ["minute: '60' out of range 0-59"]
}
```

### How it works

The API runs in **Standby mode** — send it HTTP requests directly, no run to start. Under the hood it uses battle-tested cron parsing for accurate scheduling math, adds a strict validation layer for friendly error messages, and computes run times against the timezone you specify. Impossible schedules (like `0 0 30 2 *`, February 30th) are detected and flagged rather than looping forever.

### Tips

- Encode spaces in the `expr` query string (`%20`) when testing from the command line.
- Use `base` to compute run times from a fixed point instead of "now" — handy for reproducible tests.
- Need seconds-level precision? Pass a 6-field expression.
- `tz` accepts any IANA name; a wrong name returns a clear `400` error.

### Pricing

Pay-per-event: **$0.001 per successful API call**. Readiness/health checks are never charged. No subscription, no minimums — you pay only for the requests you make.

# Actor input Schema

## Actor input object example

```json
{}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("caulleonard/cron-api").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("caulleonard/cron-api").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call caulleonard/cron-api --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,caulleonard/cron-api"
        }
    }
}

```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/23bafAbrYdHLzYOd9/builds/Yh9yjWFKxa1Z8aVoU/openapi.json
