> ## Documentation Index
> Fetch the complete documentation index at: https://developers.drpn.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Wait for the morning audit

> Poll auditReport until every check of today's audit has run, then act; with a cutoff after which a check that has not run is a miss.

To act on this morning's audit, from a sync, a chat post or a report, you first need to know it has finished. Darpan has no "audit ready" signal yet: no webhook, and no field that says the morning is done. Until there is one, poll `auditReport` for today's date and wait until no check is left at `notRun`.

## The request

```bash theme={null}
curl -s "$DARPAN_API/rest/s1/graphql/public" \
  -H "Authorization: Bearer $DARPAN_GQL_KEY" \
  -H "Content-Type: application/json" \
  -d @- <<'JSON'
{
  "query": "query Ready($audit: String!, $date: String) { auditReport(audit: $audit, date: $date) { report { date generatedAt tenant { timeZone } } health { complete summary checks { ran partial notRun } } } }",
  "variables": { "audit": "month-close", "date": "2026-12-01" }
}
JSON
```

Pass today's date in the tenant's time zone (`report.tenant.timeZone`). Do not leave `date` out here: until the audit's scheduled time, a blank `date` returns yesterday's finished report, which looks ready.

## Read the answer

`health.checks` counts the audit's configured checks for that morning:

| Field | Means |
| - | - |
| `ran` | Checks that ran over complete reads |
| `partial` | Checks that ran, but at least one read was partial or failed |
| `notRun` | Checks with no run this morning: either not run **yet**, or failed |

As each check finishes, it moves from `notRun` to `ran` or `partial`. The API cannot tell a check that has not started from one that failed: both are `notRun`. So pick a cutoff, a time by which every check has always finished on a normal morning. Before the cutoff, `notRun` means wait. After it, `notRun` means a real miss, and `health.summary` names the checks that did not run.

Once `notRun` is `0`, the morning is done. Then read `health.complete`: `true` means every read was complete; `false` means some counts may be short, as [Check this morning's audit](https://developers.drpn.ai/graphql/tasks/check-the-morning-audit.md) explains.

## A complete script

Run it from your scheduler a little after the audit's scheduled time. It polls every five minutes and exits `0` when the morning is done, or `1` at the cutoff.

```python theme={null}
import datetime, json, os, sys, time, urllib.request
from zoneinfo import ZoneInfo

API = os.environ.get("DARPAN_API", "https://api.drpn.ai") + "/rest/s1/graphql/public"
KEY = os.environ["DARPAN_GQL_KEY"]
AUDIT = "month-close"
ZONE = ZoneInfo("America/New_York")          # your tenant's report.tenant.timeZone
CUTOFF = datetime.time(8, 0)                 # after this, a check still at notRun is a miss
QUERY = """query Ready($audit: String!, $date: String) {
  auditReport(audit: $audit, date: $date) {
    report { date generatedAt }
    health { complete summary checks { ran partial notRun } }
  }
}"""

def call(variables):
    req = urllib.request.Request(API, data=json.dumps({"query": QUERY, "variables": variables}).encode(),
                                 headers={"Authorization": "Bearer " + KEY, "Content-Type": "application/json"})
    body = json.load(urllib.request.urlopen(req))
    errors = body.get("errors") or []
    if any(e.get("extensions", {}).get("code") == "THROTTLED" for e in errors):
        time.sleep(5)
        return call(variables)
    if errors:
        raise SystemExit(json.dumps(errors))
    return body["data"]["auditReport"]

today = datetime.datetime.now(ZONE).date().isoformat()
while True:
    report = call({"audit": AUDIT, "date": today})
    checks = report["health"]["checks"]
    if checks["notRun"] == 0 and checks["ran"] + checks["partial"] > 0:
        print("done", today, "complete" if report["health"]["complete"] else report["health"]["summary"])
        sys.exit(0)
    if datetime.datetime.now(ZONE).time() >= CUTOFF:
        print("cutoff passed", today, report["health"]["summary"])
        sys.exit(1)
    time.sleep(300)
```

* **`ran + partial > 0`.** An audit with no configured check has `notRun` at `0` from the start. The script treats that as not ready; `health.summary` says "No check is configured yet."
* **Cost.** Each poll costs about 35 points, far below the throttle. Polling more often than every few minutes does not get the answer sooner.

## Next

When the script exits `0`, run what depends on the morning: [Post new findings to chat](https://developers.drpn.ai/graphql/tasks/post-new-findings-to-chat.md), [Sync findings every day](https://developers.drpn.ai/graphql/tasks/sync-findings.md), or read the counts with [Check this morning's audit](https://developers.drpn.ai/graphql/tasks/check-the-morning-audit.md).

## Related

* [`auditReport` reference](https://developers.drpn.ai/graphql/queries/audit-report) and [`AuditHealth`](https://developers.drpn.ai/graphql/queries/audit-report#audithealth)
* [Cost and throttling](https://developers.drpn.ai/graphql/cost-and-throttling.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.