The Lettermint client.
lettermint =
Lettermint.new(
sending_token: System.get_env("LETTERMINT_PROJECT_TOKEN"),
team_token: System.get_env("LETTERMINT_TEAM_TOKEN")
)
lettermint = Lettermint.new("lm_...") # team or sending token, detected by its formatPass the client as the first argument to the SDK's functions:
Lettermint.EmailsandLettermint.EmailBuildersend email with the sending token (x-lettermint-token);- every other module uses the team token (
Authorization: Bearer):Lettermint.Domains,Lettermint.Messages,Lettermint.Projects,Lettermint.Projects.ReportForwarding,Lettermint.Routes,Lettermint.Stats,Lettermint.Suppressions,Lettermint.Team,Lettermint.Team.Members,Lettermint.Webhooks,Lettermint.Webhooks.Deliveries, andanalytics/3,analytics_pages/3andblocked_file_types/2below; ping/2,Lettermint.Messages.reschedule/4andLettermint.Messages.cancel/3use the team token when it is set, otherwise the sending token.
The SDK never falls back to the other token. When the token a function
needs is missing, it raises Lettermint.ConfigError before any request.
Functions that call the API return {:ok, result} (or :ok when the API
answers without a body) or {:error, error}; see Lettermint.Error.
Summary
Functions
Queries email analytics. Needs :team_token.
Queries email analytics and follows pagination.next_cursor: a lazy Stream
of whole responses, one per request. Each response carries the next page of
data.breakdown with its own meta and pagination. Needs :team_token.
The file extensions and MIME types that cannot be attached. Needs :team_token.
Creates a client from options or from a token string.
Creates a client from a token string and options. See new/1.
Checks the configured token: GET /ping returns "pong". Uses the team
token when configured, otherwise the sending token.
Functions
@spec analytics(Lettermint.Client.t(), Lettermint.Types.AnalyticsQuery.t() | map(), [ {:timeout, pos_integer()} ]) :: {:ok, Lettermint.Types.AnalyticsResponse.t()} | {:error, Lettermint.Error.t()}
Queries email analytics. Needs :team_token.
@spec analytics_pages( Lettermint.Client.t(), Lettermint.Types.AnalyticsQuery.t() | map(), [ {:timeout, pos_integer()} ] ) :: Enumerable.t(Lettermint.Types.AnalyticsResponse.t())
Queries email analytics and follows pagination.next_cursor: a lazy Stream
of whole responses, one per request. Each response carries the next page of
data.breakdown with its own meta and pagination. Needs :team_token.
A cursor expires 60 seconds after its response, so request the next page
promptly. Raises the error of a failed page request; an expired cursor is a
Lettermint.ValidationError.
@spec blocked_file_types(Lettermint.Client.t(), [{:timeout, pos_integer()}]) :: {:ok, Lettermint.Types.BlockedFileTypes.t()} | {:error, Lettermint.Error.t()}
The file extensions and MIME types that cannot be attached. Needs :team_token.
@spec new(String.t() | keyword()) :: Lettermint.Client.t()
Creates a client from options or from a token string.
Options
:sending_token: a project sending token (lm_...), forLettermint.Emails:team_token: a team API token (lm_team_...), for the Team API:base_url: default"https://api.lettermint.co/v1":timeout: milliseconds, default30_000. It covers the whole request, including reading the body. Each call can override it withtimeout:.:adapter: the HTTP adapter, a module or{module, options}; defaultLettermint.Adapter.Req. SeeLettermint.Adapter.
Pass at least one token. With a token string, the SDK picks the token type
by its format: lm_team_ followed by letters and digits is a team token,
lm_ followed by letters and digits a sending token. Any other format, such
as an SSO token (lm_sso_...), raises Lettermint.ConfigError; pass it
with :sending_token or :team_token instead. Errors never contain the
token.
Lettermint.new(sending_token: token)
Lettermint.new(token, timeout: 10_000)
@spec new(String.t(), keyword()) :: Lettermint.Client.t()
Creates a client from a token string and options. See new/1.
@spec ping(Lettermint.Client.t(), [{:timeout, pos_integer()}]) :: {:ok, String.t()} | {:error, Lettermint.Error.t()}
Checks the configured token: GET /ping returns "pong". Uses the team
token when configured, otherwise the sending token.