Skip to content

Create Monitors in Bulk With the API: A CSV Script

A Python script that reads a CSV of pages, searches and accounts, estimates the monthly credits, then creates one AyeWatch monitor per row, waiting on Retry-After and skipping rows that already exist.

By AyeWatch Team5 min read

Short answer: To create monitors in bulk, read your list from a CSV file and send one POST /api/v1/topics per row, one request at a time. Wait the Retry-After seconds when you get a 429, treat a 409 duplicate name as already done so re-runs are safe, and stop on a 403, which means a plan or credit limit.

Why one request at a time

There is no batch endpoint, so a bulk import is a loop. Two limits shape it:

  • 120 requests a minute per key, shared with any MCP client using the same key. Every response carries RateLimit-Limit, RateLimit-Remaining and RateLimit-Reset, and a 429 carries Retry-After in seconds.
  • One monitor change at a time per account. Parallel creates wait on each other and can fail with a 409 that says "Timed out waiting for another monitor change to finish."

A sequential loop avoids both and is fast enough: a few hundred rows take minutes, not hours.

The CSV format

One row per monitor. type is web_page or a source mode, target is the URL, query or link, rule is the page rule or the "Only alert me about" filter, and interval is an interval value or auto. Leave name empty to use the source's own name.

name,type,target,rule,interval
Halden tent prices,web_page,https://haldenoutdoor.example/tents/ridge-3,Alert me when the price or stock status changes.,6_hours
,x_search,"""invoice software"" -hiring lang:en",Only posts asking for a recommendation,1_day
,reddit_subreddit,https://www.reddit.com/r/smallbusiness/,Only posts asking for bookkeeping software,1_day
,linkedin_company_posts,https://www.linkedin.com/company/northwind-labs-example/,,auto
,instagram_hashtag,trailrunning,,1_day

Quotes inside a CSV field are doubled, as in the X query. Spreadsheet apps do this for you when you export.

Estimate the credits first

Creating a monitor turns it on, and its checks start spending credits. Run this before the import. A filter adds 1 credit a check to platform sources; a web page rule does not:

import csv
import sys

CREDITS = {
    "web_page": 1, "x_search": 2, "x_profile": 2, "reddit_search": 1, "reddit_subreddit": 1,
    "reddit_user": 1, "youtube_channel_videos": 1, "youtube_search": 1,
    "linkedin_post_search": 2, "linkedin_company_posts": 2, "instagram_hashtag": 2,
    "instagram_search": 2, "tiktok_hashtag": 2, "tiktok_search": 1, "tiktok_profile": 1,
}
CHECKS = {"1_hour": 720, "6_hours": 120, "12_hours": 60, "1_day": 30, "auto": 30}

with open(sys.argv[1], newline="", encoding="utf-8") as f:
    rows = list(csv.DictReader(f))

total = 0
for row in rows:
    per_check = CREDITS[row["type"]] + (1 if row["rule"] and row["type"] != "web_page" else 0)
    total += per_check * CHECKS[row["interval"]]
print(len(rows), "monitors, about", total, "credits a month")

The sample CSV comes to 120 + 90 + 60 + 60 + 60 = 390 credits, inside Pro's 500. Auto starts at one check a day and checks more often while a source is busy, so treat its 30 as a floor. An unknown type or interval stops the script with a KeyError, which is the point: fix the row before you import.

The import script

import csv
import os
import sys
import time
import requests

API = "https://ayewatch.ai/api/v1/topics"
session = requests.Session()
session.headers["Authorization"] = "Bearer " + os.environ["AYEWATCH_API_KEY"]

# The one input each single-input mode takes.
FIELD = {
    "x_search": "query", "x_profile": "handle", "reddit_search": "query",
    "reddit_subreddit": "subreddit", "reddit_user": "username",
    "youtube_channel_videos": "channel", "youtube_search": "query",
    "linkedin_post_search": "query", "linkedin_company_posts": "company",
    "instagram_hashtag": "hashtag", "instagram_search": "query",
    "tiktok_hashtag": "hashtag", "tiktok_search": "query", "tiktok_profile": "handle",
}

def body_for(row):
    body = {}
    if row["name"]:
        body["name"] = row["name"]
    if row["interval"] == "auto":
        body["monitoring_mode"] = "auto"
    else:
        body["interval"] = row["interval"]
    if row["type"] == "web_page":
        body["web_page_urls"] = [row["target"]]
        if row["rule"]:
            body["description"] = row["rule"]
    else:
        inputs = {FIELD[row["type"]]: row["target"]}
        if row["rule"]:
            inputs["filter"] = row["rule"]
        body["source"] = {"mode": row["type"], "inputs": inputs}
    return body

def create(body):
    for _ in range(5):
        resp = session.post(API, json=body, timeout=30)
        if resp.status_code == 429:
            time.sleep(int(resp.headers.get("Retry-After", "5")))
            continue
        if resp.status_code == 409 and "Timed out" in resp.json()["error"]["message"]:
            time.sleep(2)
            continue
        if resp.headers.get("RateLimit-Remaining") == "0":
            reset = int(resp.headers.get("RateLimit-Reset", "0"))
            time.sleep(min(60, max(1, reset - time.time())))
        return resp
    return resp

with open(sys.argv[1], newline="", encoding="utf-8") as f:
    rows = list(csv.DictReader(f))

with open("created.csv", "w", newline="", encoding="utf-8") as out:
    writer = csv.writer(out)
    writer.writerow(["row", "status", "id", "name_or_error"])
    for n, row in enumerate(rows, start=2):
        resp = create(body_for(row))
        data = resp.json()
        if resp.status_code == 201:
            result = [data["data"]["id"], data["data"]["name"]]
        else:
            result = ["", data["error"]["message"]]
        writer.writerow([n, resp.status_code] + result)
        if resp.status_code in (401, 403):
            print("Stopped at row", n, data["error"]["message"])
            break

Run it with python import_monitors.py monitors.csv. Row numbers in created.csv match the spreadsheet, counting the header as row 1. RateLimit-Reset is a Unix time in seconds, so the script sleeps until the window resets once it has used its last request.

Errors you will see, and what this won't do

  • 400: a bad row, such as an unknown field, a profile name where a link is needed, a filter over 200 characters or an interval your plan doesn't allow. The script records it and moves on. Don't truncate rules to fit; rewrite them.
  • 401: the key is wrong or revoked. The script stops.
  • 403: no paid plan, the active topic limit (50 on Pro, 200 on Pro+) or no credits left. The script stops.
  • 409: "A topic with this name already exists" means an earlier run created it, so re-running the whole file is safe.

The API has no dry-run mode, no batch endpoint and no endpoint for past alerts. To stage an import without spending credits, add "is_active": false to each body and turn monitors on later with PUT /api/v1/topics/{id}; turning one on needs enough credits for one check. AyeWatch Pro is $9/mo with 50 topics and hourly checks; Pro+ is $19/mo with 200 topics and ASAP mode. Every plan starts with a 7-day free trial.

Bulk import in six steps

  1. Export your list to CSV with the columns name, type, target, rule and interval.
  2. Run the estimate script and trim rows or intervals until the total fits your plan's credits.
  3. Check that the active monitors you already have plus the new rows stay under 50 on Pro or 200 on Pro+.
  4. Create an API key in API access settings and export it as AYEWATCH_API_KEY.
  5. Run the import script and read created.csv for any 400 rows.
  6. Fix those rows and run the same file again; existing monitors return 409 and are skipped.
StatusMeaningWhat the script does
201CreatedRecords the id and name
400Bad rowRecords the message, continues
401Bad or revoked keyStops
403No plan, topic limit or no creditsStops
409, name existsCreated on an earlier runRecords it, continues
409, timed outAnother monitor change was runningWaits 2 seconds, retries
429Over 120 requests a minuteSleeps Retry-After seconds, retries

Start a monitor in under a minute

Describe a topic or paste a URL. Cancel before the trial ends and you pay nothing.

Try it free for 7 days

The bottom line

Import ten rows first and read their first checks in the app. When those look right, run the full file; the duplicates from the trial run are skipped.

FAQ

Does the AyeWatch API have a bulk create endpoint?

No. Send one POST /api/v1/topics per monitor, one at a time. A sequential loop creates a few hundred monitors in minutes.

What is the AyeWatch API rate limit?

120 requests a minute per API key, shared with MCP clients that use the same key. A 429 response includes Retry-After in seconds.

Why do parallel creates fail with a 409?

AyeWatch applies one monitor change at a time per account, so parallel requests wait and can time out. Create monitors sequentially.

Can I import monitors without starting them?

Yes. Add is_active false to each body. Turn them on later with PUT /api/v1/topics/{id}; each needs enough credits for one check.

Is it safe to run the import twice?

Yes, if your names stay the same. A second create with an existing name returns 409 and the script records it and moves on.

create monitors in bulk with the apibulk create monitors csvapi rate limit retry-after pythonimport monitors from csvayewatch api bulk

Related articles