# Automating QuestDB Tasks

Learn how to automate QuestDB tasks using the REST HTTP API, or one of our recommended workflow orchestrators.

QuestDB provides a simple [HTTP API](/docs/query/rest-api/) that allows you to interact with the database using SQL queries.
This API can be leveraged for automation using Bash scripts and scheduled execution via cron jobs. This is a lightweight
approach that requires minimal dependencies.

For a more robust approach, you might want to explore the integration with workflow orchestrators such as
[Apache Airflow](/docs/integrations/orchestration/airflow/) or [Dagster](/docs/integrations/orchestration/dagster/).

## Prerequisites

- QuestDB running locally or on a server
- `curl` installed (pre-installed on most Linux/macOS systems)
- Basic knowledge of Bash or similar scripting language

## Example: Running a Scheduled Query

The following example demonstrates how to execute a query using the HTTP API:

```bash title="drop-partitions.sh"
#!/bin/bash

# QuestDB API URL
QUESTDB_URL="http://localhost:9000/exec"

# Query: Drop partitions older than 30 days
QUERY="ALTER TABLE my_table DROP PARTITION WHERE timestamp < dateadd('d', -30, now());"

# Execute the query
curl -G "$QUESTDB_URL" --data-urlencode "query=$QUERY"
```

## Automating with Cron

To execute this script daily at midnight, add the following line to your crontab:

```bash
0 0 * * * /path/to/script.sh
```

## Pros & Cons

✅ Simple to implement  \
✅ No external dependencies  \
✅ Works on any Unix-like system  \

❌ No monitoring or logging  \
❌ No built-in error handling  \
❌ No backfilling support

## Next Steps

For more advanced automation, consider using a workflow orchestrator like [**Dagster**](/docs/integrations/orchestration/dagster/) or
[**Apache Airflow**](/docs/integrations/orchestration/airflow/).

- **Full Example Repository**: [https://github.com/questdb/data-orchestration-and-scheduling-samples](https://github.com/questdb/data-orchestration-and-scheduling-samples)
