Authentication

SoilHive API uses OAuth 2.0 for security.
All API requests must be made over HTTPS and must include an authentication token.
A SoilHive client application is required to generate a token.

Using the API through this portal

  • Click Generate a token from your SoilHive client application detail page
  • Copy the token in your clipboard
  • Paste it in the "credentials" field in our API reference

Use API programmatically

  • Call /oauth/token endpoint programmatically using your SoilHive client application client_id and client_secret in the payload
  • Put the generated token in all subsequent calls to the SoilHive API with following header:
    Authorization: Bearer <TOKEN>

How to refresh a token

Tokens are valid for a limited time. The expires_in field of the /oauth/token response gives the token lifetime in seconds (for example 86400, i.e. 24 hours).

SoilHive uses the OAuth 2.0 client credentials flow, which does not issue refresh tokens. To refresh a token, call /oauth/token again with your SoilHive client application client_id and client_secret.

Recommendations:

  • Reuse the same token for all calls until it expires, instead of requesting a new token for each call
  • Request a new token shortly before the current one expires, based on expires_in, instead of hardcoding the token lifetime
  • If a call returns 401 with "detail": "Token has expired", request a new token and retry the call once

Did this page help you?