WorkOS.Client (WorkOS SDK for Elixir v3.0.1)

Copy Markdown View Source

HTTP client for the WorkOS API.

Usage

client = WorkOS.Client.new(api_key: "sk_...")

The API key falls back to the WORKOS_API_KEY environment variable.

Options for new/1

  • :api_key — API key (required unless the env var is set)
  • :client_id — client ID used by authentication flows and URL builders (falls back to the WORKOS_CLIENT_ID environment variable)
  • :base_url — override the API base URL
  • :timeout — receive timeout in milliseconds
  • :max_retries — maximum retry attempts for retryable failures
  • :req_options — extra Req options merged into every request (advanced; used by tests to inject plug: {Req.Test, ...})

Summary

Functions

Builds a fully-qualified URL for browser-redirect flows. No HTTP request is made. params become the query string; nil values are dropped.

Builds a new client. See the module documentation for options.

Performs an HTTP request against the API.

Types

t()

@type t() :: %WorkOS.Client{
  api_key: String.t(),
  base_url: String.t(),
  client_id: String.t() | nil,
  max_retries: non_neg_integer(),
  req_options: keyword(),
  timeout: pos_integer()
}

Functions

build_url(client, path, params \\ %{})

@spec build_url(t(), String.t(), map()) :: String.t()

Builds a fully-qualified URL for browser-redirect flows. No HTTP request is made. params become the query string; nil values are dropped.

new(opts \\ [])

@spec new(keyword()) :: t()

Builds a new client. See the module documentation for options.

request(client, method, path, params \\ %{}, opts \\ [])

@spec request(t(), atom(), String.t(), map(), keyword()) ::
  {:ok, term()} | {:error, WorkOS.Error.error()}

Performs an HTTP request against the API.

params is sent as query parameters for GET/DELETE/HEAD requests and as a JSON body otherwise. Per-request options:

  • :headers — extra headers, as a list of {name, value} tuples
  • :idempotency_key — explicit idempotency key header value
  • :timeout — per-request receive timeout in milliseconds
  • :max_retries — per-request retry ceiling, overriding the client's
  • :base_url — per-request base URL, overriding the client's
  • :query — extra query parameters for requests whose params is a body