Documentation Index
Fetch the complete documentation index at: https://docs.olostep.com/llms.txt
Use this file to discover all available pages before exploring further.
通过 Olostep 的 /v1/monitors 端点,你可以创建在固定时间表上运行的持久监控器,检测页面更改,并通过电子邮件或 webhook 通知你。
- 从
query、url 或两者创建一个监控器
- 每小时、每天或每周运行检查
- 将提醒发送到
email 或 webhook_url
- 列出、检查、更新和删除监控器
- 从私有快照中读取监控器快照事件
# pip install requests
import requests
创建监控器
使用 POST /v1/monitors 创建一个监控器。端点会验证你的输入,配置监控器,创建其内部时间表,并返回一个活跃的监控器对象。
query 或 url 至少需要一个。需要一个通知目标:email 或 webhook_url。
示例请求
import requests
import json
API_KEY = "<YOUR_API_KEY>"
API_URL = "https://api.olostep.com/v1"
payload = {
"query": "跟踪产品定价和库存信息的变化",
"url": "https://example.com/products/widget-pro",
"frequency": "daily",
"email": "alerts@example.com",
"metadata": {
"product_id": "widget-pro",
"team": "growth"
}
}
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
response = requests.post(f"{API_URL}/monitors", headers=headers, json=payload)
print(response.status_code)
print(json.dumps(response.json(), indent=2))
成功创建监控器会返回 HTTP 202 和一个监控器对象:
{
"id": "monitor_n8q2x4m1ak",
"object": "monitor",
"status": "active",
"schedule_id": "schedule_r4h9n2j7",
"query": "跟踪产品定价和库存信息的变化",
"url": "https://example.com/products/widget-pro",
"frequency": "daily",
"cron_expression": "0 0 * * ? *",
"notification_channel": "email",
"notification_target": "alerts@example.com",
"metadata": {
"product_id": "widget-pro",
"team": "growth"
},
"created": 1745673871,
"updated": 1745673871
}
通知渠道
每个监控器支持一个渠道:
email: 设置一个 email 字段
webhook: 设置一个 webhook_url 字段
你不能在一个请求中同时设置两者。
Webhook 示例
{
"query": "监控法律条款的变化",
"url": "https://example.com/terms",
"frequency": "weekly",
"webhook_url": "https://hooks.example.com/olostep-monitor"
}
支持的监控器频率有:
API 会根据选定的频率自动生成时间表 cron 表达式。
列出监控器
使用 GET /v1/monitors 检索你的团队的所有监控器。
默认情况下,已删除的监控器会被过滤掉。使用 ?include_deleted=true 来包含它们。
import requests
import json
API_KEY = "<YOUR_API_KEY>"
API_URL = "https://api.olostep.com/v1"
headers = {
"Authorization": f"Bearer {API_KEY}"
}
response = requests.get(f"{API_URL}/monitors", headers=headers)
result = response.json()
print(f"Total monitors: {result['count']}")
print(json.dumps(result, indent=2))
获取一个监控器
使用 GET /v1/monitors/:monitor_id 检索单个监控器。
import requests
import json
API_KEY = "<YOUR_API_KEY>"
API_URL = "https://api.olostep.com/v1"
MONITOR_ID = "monitor_n8q2x4m1ak"
headers = {
"Authorization": f"Bearer {API_KEY}"
}
response = requests.get(f"{API_URL}/monitors/{MONITOR_ID}", headers=headers)
print(json.dumps(response.json(), indent=2))
列出监控器事件
使用 GET /v1/monitors/:monitor_id/events 列出监控器的快照事件。
此端点支持分页:
limit(默认 25,最大 100)
cursor(来自先前响应的不透明分页令牌)
事件按最新优先返回。每个项目都包含一个短期有效的预签名 snapshot_url,以便你可以安全地获取私有快照内容。
import requests
import json
API_KEY = "<YOUR_API_KEY>"
API_URL = "https://api.olostep.com/v1"
MONITOR_ID = "monitor_n8q2x4m1ak"
headers = {
"Authorization": f"Bearer {API_KEY}"
}
response = requests.get(
f"{API_URL}/monitors/{MONITOR_ID}/events?limit=10",
headers=headers
)
print(json.dumps(response.json(), indent=2))
响应格式
{
"data": [
{
"id": "run_v7k2p9m3",
"run_id": "run_v7k2p9m3",
"created": 1777960800,
"changed": true,
"summary": "价格从 $49 改变为 $45,库存变为低可用性。",
"snapshot_url": "https://olostep-monitor-snapshot.s3.amazonaws.com/private/key?...signature..."
}
],
"has_more": false,
"next_cursor": null
}
如果 cursor 格式错误,端点会返回:
{
"error": "Invalid cursor."
}
更新监控器
使用 POST /v1/monitors/:monitor_id 更新监控器。
支持的更新:
metadata(与现有元数据合并;传递空字符串值以删除键)
frequency(hourly、daily、weekly)
如果你更新 frequency,API 会在内部重新创建监控器时间表。
示例请求
import requests
import json
API_KEY = "<YOUR_API_KEY>"
API_URL = "https://api.olostep.com/v1"
MONITOR_ID = "monitor_n8q2x4m1ak"
payload = {
"frequency": "hourly",
"metadata": {
"owner": "ops-team",
"deprecated_field": ""
}
}
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
response = requests.post(
f"{API_URL}/monitors/{MONITOR_ID}",
headers=headers,
json=payload
)
print(json.dumps(response.json(), indent=2))
删除监控器
使用 DELETE /v1/monitors/:monitor_id 删除监控器。
删除是对监控器行的软删除(status 变为 deleted),同时也会移除与该监控器相关的内部调度/影子代理资源。
import requests
import json
API_KEY = "<YOUR_API_KEY>"
API_URL = "https://api.olostep.com/v1"
MONITOR_ID = "monitor_n8q2x4m1ak"
headers = {
"Authorization": f"Bearer {API_KEY}"
}
response = requests.delete(f"{API_URL}/monitors/{MONITOR_ID}", headers=headers)
print(json.dumps(response.json(), indent=2))
常见验证错误
监控器端点会为常见的无效请求返回清晰的验证错误:
- 缺少
query 和 url
- 缺少
frequency,或不支持的频率值
- 缺少
email 和 webhook_url
- 同时提供
email 和 webhook_url
- 无效的电子邮件格式
- 无效的 webhook URL(必须是
http 或 https)
- 无效的
monitor_id 格式
示例错误:
{
"error": "'frequency' must be one of: hourly, daily, weekly."
}