# Consume Timesheets integrations

Canonical references: [Timesheets developer manual](https://timesheets.deckfamilyfarm.com/developer-manual)
and the Timesheets repository's `integrations/README.md`. The catalog records the
reviewed revision. Configuration belongs to the source application, not Reports.

## Launch and link an application

Timesheets owns identity, permissions, enterprise/task selection and optional
record links. A module owns its records, calculations, interface and local session.
Provide a version-1 module manifest with `moduleKey`, label, remote/local URLs,
launch authentication, capabilities, and optional task bindings and aliases.
A Timesheets administrator registers it and grants access.

Timesheets POSTs form data to the module's configured launch path, commonly
`/api/auth/timesheets-launch`. It includes `access_token`, `module_key`,
`capability_key`, relative redirect paths, record date and optional time-entry IDs.
Verify the token server-side with:

```http
POST https://timesheets.deckfamilyfarm.com/api/auth/getUserRole
Authorization: Bearer <user-access-token>
```

Create an HTTP-only module session after verification and enforce module access.
Accept only same-app relative redirects. Derive identity and access from the
verified response, not launch labels. Keep secrets out of browser code and logs.

Dashboard-only modules use `taskBindings: []` and need no callback secret. Modules
that link saved operational records send a server-side callback to
`POST /api/integrations/{moduleKey}/links` with `X-Integration-Secret`, the launch
token, capability, stable record type/ID, date, action and summary. Follow the
canonical guide's full shape and idempotency rules. A time-entry ID may not exist
until the employee saves the row; preserve the launch context for later attachment.

## Read reporting data

The launch contract does not grant a generic reporting credential. Prefer verified
private dataset releases for reporting. Source read APIs retain their own access
and scope rules; documented examples include:

| Interface | Scope and access |
| --- | --- |
| `POST /api/user/timesheets/week` | Authenticated user report; explicit `start_date`, `end_date`, enterprise/task and approval filters. Authorization determines visible records. |
| `GET /api/integrations/poultry/labor-report?startDate=YYYY-MM-DD&endDate=YYYY-MM-DD` | Poultry service report for Layers/Roasters, with daily/task hours and wage-plus-fringe cost; not a farm-wide export. |

The Poultry report accepts a configured Poultry service token as a bearer token or
`X-Integration-Secret`. These are deployment credentials verified against the
Timesheets `POULTRY_SERVICE_TOKEN`/`POULTRY_INTEGRATION_TOKEN` configuration; do not
invent a credential from a module callback secret. A consumer may load its
configured credential from `TIMESHEETS_SERVICE_TOKEN` or its documented aliases.
Ask the deployment owner to provision missing access through the normal private
configuration process; never request a secret in chat.

The current Poultry labor calculation includes recorded entries without an
approval filter. Its calculated wage cost does not prove wages were paid. Preserve
that scope when comparing it to approved-only labor datasets. Explicit date ranges
avoid the user report's summary-window defaults, which can include a partial week.

For raw Timesheets entries or cross-enterprise work, use an explicitly read-only
capture with declared fields, approval status, date basis, and source provenance.
Do not start Timesheets to harvest data: startup can initialize schemas and jobs.
