CropPath for developers

All guides

Authentication

Available

Which credential a system uses, what it may call, and the answers that ask for one more step.

A system calls the API with a bearer credential: an API token (agt_…) or an access token of an OAuth2 client (ago_…). Send it as Authorization: Bearer <token>. The admin console uses a session cookie instead, and a few routes accept only that (see below). A missing, unknown, revoked or expired credential is refused with 401 missing_or_invalid_token.

API tokens

A company admin creates an API token in the admin console (Settings, Integrations). It has a name, a role (tenant_admin, operator or auditor) and an optional expiry of 1 to 3650 days. The token is shown once. A company holds at most 100 live tokens.

A token carries a role but no list of facilities, so an operator token is refused (403 role_not_permitted) on every route that limits operators to their own facilities. For that work, use an OAuth2 client of role operator, which carries its facilities.

OAuth2 client credentials

A company admin registers an API client in the admin console (Settings, Integrations) with a role, its scopes and, for an operator client, its facilities (none means every facility). The client id (agc_…) is public; the secret (acs_…) is shown once. A company holds at most 50 clients that are not revoked.

The client asks POST /v1/oauth/token for an access token (RFC 6749 client credentials) with a form body. It authenticates with HTTP Basic or with client_id and client_secret in the body, never both. scope (names separated by spaces) asks for fewer scopes; without it the token gets all of the client's. The token is valid for 900 seconds: ask for a new one when it expires, not one per request. A client holds at most 20 live tokens.

curl -sS https://<host>/v1/oauth/token \
  -u "$CROPPATH_CLIENT_ID:$CROPPATH_CLIENT_SECRET" \
  -d grant_type=client_credentials \
  --data-urlencode "scope=lot_read lot_write"
# {"access_token": "ago_...", "token_type": "Bearer", "expires_in": 900, "scope": "lot_read lot_write"}

POST /v1/oauth/revoke (RFC 7009) ends a token early. Revoking the client in the console ends all of its tokens at once.

Scopes

Each scope is the name of one permission and allows every route that carries it, within the client's role. A route whose permission is not among the token's scopes answers 403 role_not_permitted. epcis_capture, records_export and webhook_admin are granted only by name: no other scope includes them. The API reference says what each scope allows. The scopes are:

Routes for signed-in people only

Some routes need a person signed in to the console and refuse every API token and API client with 403 role_not_permitted: API tokens and API clients themselves, team members and invitations, the company's sign-in security, the full company export, notifications, support requests, usage and limits, the getting-started checklist, proposing a facility, personal data requests and the company's offboarding state (GET /v1/company/offboarding). The routes of a signed-in session under /v1/auth/, such as GET /v1/auth/me, answer 401 not_authenticated without the session cookie. An API client also never gets the company profile or the harvest app's key registrations: no scope exists for them.

Recent sign-in and two-step sign-in

Sensitive routes, such as creating an API token or API client, rotating a webhook secret and the full company export, need a password confirmed within the last 10 minutes. An older session gets 401 reauthentication_required: the browser sends the password to POST /v1/auth/reauth and repeats the request. A session that must use two-step sign-in and has not entered its code gets 403 two_factor_required on most API routes. Only the session's own routes under /v1/auth/ (where it enters the code), GET /v1/help and the routes that need no credential never ask for it. On an account with two-step sign-in, revoking a signing key, a lab key or an issuer key, recalling or withdrawing a lot and adding a market limit also need a code from the authenticator app (or a backup code) confirmed within the last 5 minutes. An older session gets 401 mfa_step_up_required: the browser sends the password with the code to POST /v1/auth/reauth and repeats the request. An account without two-step sign-in is not asked for this step. API tokens and API clients are never asked for any of these steps.

The X-Tenant header

A token belongs to one company. With a token X-Tenant is optional; a value other than the token's company is refused with 403 tenant_not_allowed. A person who belongs to several companies chooses one with X-Tenant (without it, their first membership); CropPath staff act for a company the same way. A company the caller may not act for answers 403 tenant_not_allowed.

In the API reference