> ## 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.

# Post new findings to chat

> Read the findings first found this morning with findings, and post each one to a Slack or Google Chat incoming webhook, once.

Once this morning's audit has finished, read the findings it found for the first time and post each one to your team's chat room. Keep the ids you have posted, so a retry or a second run never posts the same finding twice.

## 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 New($q: String, $after: String) { findings(first: 100, query: $q, after: $after) { edges { node { id audit statement priority headline next } } pageInfo { hasNextPage endCursor } } }",
  "variables": { "q": "state:open firstFound:2026-12-01" }
}
JSON
```

`firstFound:2026-12-01` matches findings a check first reported that morning; use today's date in the tenant's time zone. `state:open` leaves out any that were already fixed. Add `audit:month-close` or `priority:P0,P1` to narrow it. See [List open findings](https://developers.drpn.ai/graphql/tasks/list-open-findings.md#filter).

Each node's `next` is a [Darpan CLI](https://docs.drpn.ai/getting-started/set-up-darpan-cli) command, such as `darpan findings show F-20761`, that prints the whole finding. Put it in the message so anyone with the CLI can paste it.

## Post one message

Slack and Google Chat incoming webhooks both take a JSON body with a `text` field:

```bash theme={null}
curl -s -X POST "$CHAT_WEBHOOK_URL" \
  -H "Content-Type: application/json; charset=UTF-8" \
  -d '{"text": "P1 · month-close R8 · Return M258615 has no credit memo\n`darpan findings show F-20761`"}'
```

Create the webhook in Slack (an app with **Incoming Webhooks**) or in a Google Chat space (**Apps & integrations** › **Webhooks**). Treat its URL as a secret: anyone who has it can post to the room.

## A complete script

Run it after [Wait for the morning audit](https://developers.drpn.ai/graphql/tasks/wait-for-the-morning-audit.md) exits `0`. It reads every page, skips ids it has already posted, and records each id as soon as its message is sent.

```python theme={null}
import datetime, json, os, 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"]
WEBHOOK = os.environ["CHAT_WEBHOOK_URL"]     # Slack or Google Chat incoming webhook
ZONE = ZoneInfo("America/New_York")          # your tenant's report.tenant.timeZone
POSTED = "posted-findings.txt"               # ids already posted, one per line
QUERY = """query New($q: String, $after: String) {
  findings(first: 100, query: $q, after: $after) {
    edges { node { id audit statement priority headline next } }
    pageInfo { hasNextPage endCursor }
  }
}"""

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"]["findings"]

def post(text):
    req = urllib.request.Request(WEBHOOK, data=json.dumps({"text": text}).encode(),
                                 headers={"Content-Type": "application/json; charset=UTF-8"})
    urllib.request.urlopen(req).read()
    time.sleep(1)                            # stay under the webhook's rate limit

posted = set(open(POSTED).read().split()) if os.path.exists(POSTED) else set()
today = datetime.datetime.now(ZONE).date().isoformat()
after = None
while True:
    page = call({"q": "state:open firstFound:" + today, "after": after})
    for edge in page["edges"]:
        f = edge["node"]
        if f["id"] in posted:
            continue
        post(f"{f['priority']} · {f['audit']} {f['statement']} · {f['headline']}\n`{f['next']}`")
        posted.add(f["id"])
        with open(POSTED, "a") as out:
            out.write(f["id"] + "\n")
    if not page["pageInfo"]["hasNextPage"]:
        break
    after = page["pageInfo"]["endCursor"]
```

* **Dedupe by `id`.** A finding keeps its `id` from the morning it is found until it is fixed. The script writes each id after its message is sent, so a run that stops halfway picks up where it left off.
* **A busy morning.** Dozens of messages bury a room. To post one line instead, read `auditReport { summary { newToday } }` and post the count with a link to the audit in Darpan.
* **Only some findings.** Add `priority:P0,P1` to the query to post the urgent ones, and leave the rest to [Sync findings every day](https://developers.drpn.ai/graphql/tasks/sync-findings.md).

## Related

* [`findings` reference](https://developers.drpn.ai/graphql/queries/findings) and [`FindingListItem`](https://developers.drpn.ai/graphql/queries/findings#findinglistitem)
* [Pagination](https://developers.drpn.ai/graphql/pagination.md) · [Search syntax](https://developers.drpn.ai/graphql/search-syntax.md)


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