Checking order status by hand is fine for five orders. At fifty a day it eats your morning. Most /api/v2 panels let you ask about up to 100 orders in a single status call, so a small cron job can do the checking and only bother you when an order is stuck.
What we want
- Check every open order once an hour.
- Stay quiet when everything is fine.
- Send one short alert listing orders that are stuck, partial or canceled.
The multi-status call
Instead of order=123, send orders=123,124,125. The panel returns a dict keyed by order id:
{"123": {"status": "Completed", "remains": "0"},
"124": {"status": "In progress", "remains": "340"},
"125": {"status": "Partial", "remains": "120"}}
The script
import os, sqlite3, time, requests
API_URL, API_KEY = os.environ["PANEL_URL"], os.environ["PANEL_KEY"]
STUCK_AFTER = 6 * 3600 # seconds
db = sqlite3.connect("orders.db")
open_rows = db.execute("SELECT id, created_at FROM orders WHERE done = 0").fetchall()
problems = []
for i in range(0, len(open_rows), 100):
chunk = open_rows[i:i + 100]
ids = ",".join(str(r[0]) for r in chunk)
res = requests.post(API_URL, data={"key": API_KEY, "action": "status", "orders": ids}, timeout=30).json()
for oid, created in chunk:
s = res.get(str(oid), {}).get("status", "Unknown")
if s in ("Completed", "Partial", "Canceled"):
db.execute("UPDATE orders SET done = 1, status = ? WHERE id = ?", (s, oid))
if s in ("Partial", "Canceled") or (s != "Completed" and time.time() - created > STUCK_AFTER):
problems.append(f"{oid}: {s}")
db.commit()
if problems:
print("Orders needing attention:\n" + "\n".join(problems)) # pipe this to mail or a chat webhook
Run it with cron and pipe the output to mail. If there is no output, cron sends nothing.
Tips
- Store
created_atwhen you place the order so "stuck" has a clear meaning. - Treat "Unknown" as a warning, not a failure. It often means a typo in the id.
- Keep the threshold per service if some services are slow by design.
I built this for orders placed on the SMMYodha panel, but it works anywhere the API follows the same layout. For background on what each order state means, see this beginner guide to SMM panels.
Written by MD Fozla Rabbi, SEO Specialist.
Top comments (0)