# Foundation: client, keys and webhooks

Generated 2026-12-01 from the Everee docs (branch v1.0). Part of https://files.everee.com/everee-payroll-infrastructure-explainer.md

```text
GOAL
Build the shared foundation every Everee area depends on: a server-side API client, secrets handling, a webhook receiver, and an error and retry policy.

READ FIRST (each page also has a Markdown version at the same URL with .md added; the docs index is https://developer.everee.com/llms.txt)
- https://developer.everee.com/docs/getting-your-partner-api-key
- https://developer.everee.com/docs/authentication-api-tokens
- https://developer.everee.com/docs/support-and-operations
- https://developer.everee.com/docs/rate-limits
- https://developer.everee.com/docs/requests-responses
- https://developer.everee.com/docs/events-overview
- https://developer.everee.com/docs/authenticating-events
- https://developer.everee.com/docs/securing-your-handler
- https://developer.everee.com/docs/sandbox-and-production
- https://developer.everee.com/docs/multiple-ein-company-instances

BUILD
- One API client with two credentials: partner keys (a test key zk_test_... and a production key zk_prod_...) for the Company Onboarding API, and a per-company key (tsk_...) with the x-everee-tenant-id header for everything else. Store a key and company id per company (one per EIN).
- A webhook receiver: read the raw body, verify the HMAC-SHA256 signature of timestamp + '.' + raw body against the x-everee-webhook-signature header (it may carry several v1= signatures during a key rotation: accept any), check the timestamp, return 2xx quickly and process asynchronously.
- Store each delivery's id and ignore repeats. Events can arrive more than once and out of order, so treat an event as a nudge and read current state from the API.
- Manage endpoints and keys through the API: Webhook Endpoints API (up to three endpoints per company, rotate signing key, send test event) and Company API keys (rotate, expire; shown once).
- Error handling: surface 4xx messages to the user, retry 5xx and 429 with backoff, and log the X-Request-ID response header with every failure so Everee support can trace it.

OPERATIONS (all paths are under https://api.everee.com/integration/v1; each reference page, with .md added, lists its request and response fields)
- GET /webhook-endpoints | operationId list-webhook-endpoints | https://developer.everee.com/reference/list-webhook-endpoints.md
- POST /webhook-endpoints | operationId create-webhook-endpoint | https://developer.everee.com/reference/create-webhook-endpoint.md
- PUT /webhook-endpoints/{id} | operationId update-webhook-endpoint | https://developer.everee.com/reference/update-webhook-endpoint.md
- DELETE /webhook-endpoints/{id} | operationId delete-webhook-endpoint | https://developer.everee.com/reference/delete-webhook-endpoint.md
- POST /webhook-endpoints/{id}/rotate-signing-key | operationId rotate-webhook-endpoint-signing-key | https://developer.everee.com/reference/rotate-webhook-endpoint-signing-key.md
- POST /webhook-endpoints/{id}/test | operationId send-test-webhook-event | https://developer.everee.com/reference/send-test-webhook-event.md
- GET /partner/companies/{companyId}/api-keys | operationId list-partner-company-api-keys | https://developer.everee.com/reference/list-partner-company-api-keys.md
- POST /partner/companies/{companyId}/api-keys | operationId create-partner-company-api-key | https://developer.everee.com/reference/create-partner-company-api-key.md
- POST /partner/companies/{companyId}/api-keys/{keyId}/rotate | operationId rotate-partner-company-api-key | https://developer.everee.com/reference/rotate-partner-company-api-key.md
- PUT /partner/companies/{companyId}/api-keys/{keyId}/expiration | operationId set-partner-company-api-key-expiration | https://developer.everee.com/reference/set-partner-company-api-key-expiration.md
- DELETE /partner/companies/{companyId}/api-keys/{keyId}/expiration | operationId cancel-partner-company-api-key-expiration | https://developer.everee.com/reference/cancel-partner-company-api-key-expiration.md

RULES
- Build every flow as a loop around reads that tell you what is left: make a change, read the state again (readiness.missing for onboarding, a run's blockers and the requirements behind them for payroll, a funding's status and resolutionInstructions), and act on what is left. Never hard-code the steps: codes appear and disappear. Map each code you know to a screen, and show resolutionInstructions for any you don't. Use webhooks (company-onboarding.status-changed, requirement.created, payroll-run.status-changed) to know when to read again, not instead of the read. A requirement does NOT open when a worker is created or changed: it opens only when a payroll calculation or a returned deposit finds the problem, so calculate runs early.
- Base URL https://api.everee.com/integration/v1. The partner key is the HTTP Basic user name for the Company Onboarding API: the test key (zk_test_...) creates and reaches only Sandbox companies and the production key (zk_prod_...), issued after Everee approves the integration, only Production companies. A company in the other environment returns 404. The company key (tsk_...) is the HTTP Basic user name for everything else, plus an x-everee-tenant-id header holding the company's id.
- Keep every key on the server. Everee rejects browser requests. Read keys from a secrets store, never log them, never hard-code them.
- Rate limit: 100 operations per 5 seconds per key (see the RateLimit-Policy header). Back off on 429.
- Only payables and payroll run items have an idempotency key (externalId). Make other creates safe yourself: look first, keep the Everee ID next to your own record.
- Test against a sandbox instance (tsk_test_... keys) before production. Nothing in a URL selects the environment; the key does. Sandbox company creation is limited (25 alive at once, 50 created in any rolling 7 days; evaluation access before the agreement is signed: 1 and 2, 14 days, companies created without an agreement), and each Sandbox company is limited to 250 workers, 100 off-cycle runs in 7 days and 100 payroll calculations in 24 hours: a refused request returns 429 with when the next can be created, and a sandbox company you no longer need can be retired.

DONE WHEN
- A signed test event from 'Send a test event' is accepted, and the same body with a tampered byte is rejected.
- A sandbox call with the company key and tenant header succeeds, and a call from a browser is not possible.

TESTS TO WRITE
- A signed test event from 'Send a test event' is accepted, and the same body with one byte changed is rejected.
- A delivery whose header carries two v1 signatures (during a key rotation) is accepted when either matches.
- The same event id delivered twice is processed once.
- A 429 or 5xx is retried with backoff, and a 4xx message reaches the user.
- No log line, error report or response ever contains a key. Assert it with a redaction test.

If a fact you need isn't in the docs, ask me. Don't guess endpoint paths, field names or business rules.
```
