View Source ExPipedrive.Client (ex_pipedrive v0.1.0)

Builds authenticated Tesla clients for the Pipedrive API.

Centralizes base URL / api_domain handling. Pass either a full URL (https://company.pipedrive.com) or a host (company.pipedrive.com); versioned paths (/api/v2, /api/v1) are owned by ExPipedrive.Request.

API token auth

By default, API tokens are sent via the x-api-token header (compatible with Pipedrive API v1 and v2). Legacy query-param auth (?api_token=...) is available only via auth: :query for transitional v1 callers and should not be used for new code.

OAuth

Prefer from_token/2 with an ExPipedrive.Oauth.Token bundle. Use ExPipedrive.Oauth.ensure_fresh/4 (and a TokenStore) before building a client when tokens may be near expiry. from_oauth/4 remains a one-shot refresh helper for scripts.

Retries, telemetry, and middleware

By default clients include:

Options on new/3 and from_token/2:

  • :retrytrue (default), false, or keyword opts for the retry middleware
  • :telemetrytrue (default), false, or keyword opts (:metadata, …)
  • :middleware — extra Tesla middleware list (innermost, closest to adapter)
  • :adapter — optional Tesla adapter (tests)

Summary

Functions

Normalizes an api_domain or base URL to an absolute URL without a trailing slash.

Builds a Tesla client by refreshing an OAuth access token once.

Builds a Tesla client from an OAuth Token (Bearer + api_domain).

Ensures the token is fresh (refreshing if needed), optionally persists it, and builds a Tesla client.

Builds a Tesla client authenticated with a Pipedrive API token.

Types

@type auth_mode() :: :header | :query

Functions

@spec base_url(String.t()) :: String.t()

Normalizes an api_domain or base URL to an absolute URL without a trailing slash.

Link to this function

from_oauth(refresh_token, client_id, client_secret, api_domain, opts \\ [])

View Source
@spec from_oauth(String.t(), String.t(), String.t(), String.t(), keyword()) ::
  {:ok, Tesla.Client.t()} | {:error, term()}

Builds a Tesla client by refreshing an OAuth access token once.

Returns {:ok, client} or {:error, reason} from the token refresh. Prefer from_token/2 / from_token_store/4 when you already hold a Token.

Link to this function

from_token(token, opts \\ [])

View Source
@spec from_token(
  ExPipedrive.Oauth.Token.t(),
  keyword()
) :: Tesla.Client.t()

Builds a Tesla client from an OAuth Token (Bearer + api_domain).

Does not refresh. Call Oauth.ensure_fresh/4 first when needed.

Accepts the same :retry, :telemetry, :middleware, and :adapter options as new/3.

Link to this function

from_token_store(token, client_id, client_secret, opts \\ [])

View Source
@spec from_token_store(ExPipedrive.Oauth.Token.t(), String.t(), String.t(), keyword()) ::
  {:ok, Tesla.Client.t(), ExPipedrive.Oauth.Token.t()} | {:error, term()}

Ensures the token is fresh (refreshing if needed), optionally persists it, and builds a Tesla client.

Options:

  • :store / :store_id — when both set, saves the (possibly refreshed) token
  • :skew_seconds, :adapter, and other Oauth.ensure_fresh/4 options
  • plus from_token/2 middleware options (:retry, :telemetry, :middleware)
Link to this function

new(api_token, api_domain, opts \\ [])

View Source
@spec new(String.t(), String.t(), keyword()) :: Tesla.Client.t()

Builds a Tesla client authenticated with a Pipedrive API token.

Options

  • :auth:header (default) sends x-api-token; :query is isolated legacy v1 query-param auth (api_token) for transitional use only.
  • :retrytrue (default), false, or keyword options for ExPipedrive.Middleware.Retry
  • :telemetrytrue (default), false, or keyword options for ExPipedrive.Middleware.Telemetry
  • :middleware — additional Tesla middleware (after core stack)
  • :adapter — optional Tesla adapter (used in tests).