observation-js Documentation - v1.14.0
    Preparing search index...

    Class ObservationClient

    Index

    Constructors

    Properties

    observations: Observations
    species: Species
    regions: Regions
    locations: Locations
    regionSpeciesLists: RegionSpeciesLists
    users: Users
    countries: Countries
    badges: Badges
    groups: Groups
    exports: Exports
    languages: Languages
    lookups: Lookups
    nia: Nia
    media: Media
    sessions: Sessions
    challenges: Challenges
    interceptors: {
        request: InterceptorManager<FetchOptions>;
        response: InterceptorManager<Response>;
    }

    Methods

    • Sets the language for the Accept-Language header in all subsequent API requests. The default language is 'en'.

      Parameters

      • language: string

        The two-letter language code (e.g., 'nl', 'en', 'de').

      Returns void

    • Internal

      Gets the base URL for the API.

      Returns string

      The base URL.

    • Generates the authorization URL for the OAuth2 Authorization Code Grant flow. The user should be redirected to this URL to authorize the application.

      Parameters

      • state: string

        A random string to protect against CSRF attacks.

      • scope: string[]

        An array of scopes the application is requesting.

      Returns string

      The full authorization URL to redirect the user to.

      If the client options (clientId, redirectUri) are not configured.

    • Exchanges an authorization code for an access token using the Authorization Code Grant flow.

      Parameters

      • code: string

        The authorization code received from the callback URL after user authorization.

      Returns Promise<TokenResponse>

      A promise that resolves to the token response from the API.

      If the token request fails.

      If the client options are not configured.

    • Fetches an access token using the Resource Owner Password Credentials Grant. Use this grant type only for trusted applications.

      Parameters

      Returns Promise<TokenResponse>

      A promise that resolves to the token response.

      If the token request fails.

    • Refreshes an expired access token using a refresh token.

      Returns Promise<TokenResponse>

      A promise that resolves to the new token response.

      If the refresh token request fails.

      If the refresh token or client options are not available.

    • Manually sets the access token for the client to use in subsequent authenticated requests.

      Parameters

      • token: string

        The access token.

      Returns void

    • Internal

      Manually sets the refresh token for the client.

      Parameters

      • token: string

        The refresh token.

      Returns void

    • Checks if an access token is currently set on the client.

      Returns boolean

      true if an access token is set, false otherwise.

    • Checks if a refresh token is currently set on the client.

      Returns boolean

      true if a refresh token is set, false otherwise.

    • Internal

      Gets the current access token.

      Returns null | string

      The access token or null if not set.

    • Makes an authenticated request to the API. An access token must be set via setAccessToken or by using one of the authentication flows.

      Type Parameters

      • T

      Parameters

      • endpoint: string

        The API endpoint to request.

      • options: FetchOptions = {}

        Optional request options, including URL parameters.

      Returns Promise<T>

      A promise that resolves to the JSON response.

      If the access token is not set or the request is unauthorized.

      If the API request fails for other reasons.

    • Makes a public (unauthenticated) request to the API.

      Type Parameters

      • T

      Parameters

      • endpoint: string

        The API endpoint to request.

      • options: FetchOptions = {}

        Optional request options, including URL parameters.

      Returns Promise<T>

      A promise that resolves to the JSON response.

      If the API request fails.