# Flag packages on failed lab results

A failed lab test (microbial contamination, pesticide levels, potency mismatch) means a package needs to come off the shelf immediately, not whenever someone happens to check. Wire this up as an event handler, not a periodic report.

## Subscribe to lab result events

`POST /v1/webhooks/` with `events: ["lab_result.received"]`. Every new lab result attached to a package in the connection fires this event, pass or fail.

## Check the result in your handler

The event's `data` gives you the lab result, including `passed` and the failed panel, if any (potency, pesticides, microbials, etc.). Filter for `passed: false` in your handler. Passing results usually need no action beyond your own audit log.

## Look up the affected package

Use the lab result's package reference to call `GET /v1/connections/{connection_id}/facilities/{facility_id}/packages/{package_id}` and confirm current status. Production packages are read-only through SeedLink, so reflect the hold in your own system (block it from checkout, flag it in your inventory view) rather than trying to write the hold back upstream.

## Test the handler before it matters

`POST /v1/sandbox/{connection_id}/simulate` with `"scenario": "lab_result_received"` and a `params.result` of `"fail"` fires a synthetic failing result at a sandbox package, so you can build and test the handler without waiting on a real lab.

