MillionSend.Contacts (MillionSend v0.5.0)

Copy Markdown View Source

Contacts are team-global (one per email per team, case-insensitive) and addressable by id or email — email wins when both are given.

Input maps are sent as given: create/2 accepts email, first_name, last_name, unsubscribed, properties, segments ([%{id: ...}]) and topics ([%{id: ..., subscription: ...}]); update/2 accepts first_name, last_name, unsubscribed and properties, where nil clears a field.

MillionSend.Contacts.create(%{email: "ada@acme.dev", first_name: "Ada"})
MillionSend.Contacts.get(%{email: "ada@acme.dev"})
MillionSend.Contacts.get("contact-uuid")
MillionSend.Contacts.update(%{id: id, unsubscribed: true, first_name: nil}) # nil clears

Summary

Functions

POST /contacts/:id_or_email/segments/:segment_id — add the contact to a segment.

POST /contacts. A duplicate email (per team, case-insensitive) is a 409 validation_error.

POST /contacts/batch — 1..1000 create/2 payloads in one call. Options: on_conflict: (:error, the default, :skip or :upsert; sent as the query parameter) and batch_validation: (:strict, the default, or :permissive; sent as the x-batch-validation header). Returns a MillionSend.Contacts.BatchResponse; only permissive mode fills errors.

GET /contacts/:id_or_email — by id/email map or a bare id string.

GET /contacts — accepts limit:, after:, before:.

GET /contacts/:id_or_email/topics — every topic with the contact's effective subscription ("opt_in" | "opt_out") and whether it is explicit or the topic's default. Returns a MillionSend.List of TopicSubscriptions.

DELETE /contacts/:id_or_email — by id/email map or a bare id string.

DELETE /contacts/:id_or_email/segments/:segment_id — remove the contact from a segment.

PATCH /contacts/:id_or_email. Include a key with nil to clear it; omit to leave unchanged.

PATCH /contacts/:id_or_email/topics — set per-topic subscriptions. params carries the address plus topics: as a list of %{id: ..., subscription: :opt_in | :opt_out}.

Types

address()

@type address() :: String.t() | map()

Functions

add_to_segment(client \\ MillionSend.client(), address, segment_id)

@spec add_to_segment(MillionSend.Client.t(), address(), String.t()) ::
  {:ok, MillionSend.Contacts.Contact.t()} | {:error, MillionSend.Error.t()}

POST /contacts/:id_or_email/segments/:segment_id — add the contact to a segment.

create(client \\ MillionSend.client(), params)

@spec create(MillionSend.Client.t(), map()) ::
  {:ok, MillionSend.Contacts.Contact.t()} | {:error, MillionSend.Error.t()}

POST /contacts. A duplicate email (per team, case-insensitive) is a 409 validation_error.

create_batch(list)

@spec create_batch([map()]) ::
  {:ok, MillionSend.Contacts.BatchResponse.t()}
  | {:error, MillionSend.Error.t()}

POST /contacts/batch — 1..1000 create/2 payloads in one call. Options: on_conflict: (:error, the default, :skip or :upsert; sent as the query parameter) and batch_validation: (:strict, the default, or :permissive; sent as the x-batch-validation header). Returns a MillionSend.Contacts.BatchResponse; only permissive mode fills errors.

create_batch(client, list)

@spec create_batch(MillionSend.Client.t() | [map()], [map()] | keyword()) ::
  {:ok, MillionSend.Contacts.BatchResponse.t()}
  | {:error, MillionSend.Error.t()}

create_batch(client, list, opts)

@spec create_batch(MillionSend.Client.t(), [map()], keyword()) ::
  {:ok, MillionSend.Contacts.BatchResponse.t()}
  | {:error, MillionSend.Error.t()}

get(client \\ MillionSend.client(), address)

GET /contacts/:id_or_email — by id/email map or a bare id string.

list()

GET /contacts — accepts limit:, after:, before:.

list(client)

@spec list(MillionSend.Client.t() | keyword()) ::
  {:ok, MillionSend.List.t()} | {:error, MillionSend.Error.t()}

list(client, opts)

@spec list(
  MillionSend.Client.t(),
  keyword()
) :: {:ok, MillionSend.List.t()} | {:error, MillionSend.Error.t()}

list_topics(client \\ MillionSend.client(), address)

@spec list_topics(MillionSend.Client.t(), address()) ::
  {:ok, MillionSend.List.t()} | {:error, MillionSend.Error.t()}

GET /contacts/:id_or_email/topics — every topic with the contact's effective subscription ("opt_in" | "opt_out") and whether it is explicit or the topic's default. Returns a MillionSend.List of TopicSubscriptions.

remove(client \\ MillionSend.client(), address)

DELETE /contacts/:id_or_email — by id/email map or a bare id string.

remove_from_segment(client \\ MillionSend.client(), address, segment_id)

@spec remove_from_segment(MillionSend.Client.t(), address(), String.t()) ::
  {:ok, MillionSend.Contacts.Contact.t()} | {:error, MillionSend.Error.t()}

DELETE /contacts/:id_or_email/segments/:segment_id — remove the contact from a segment.

update(client \\ MillionSend.client(), params)

@spec update(MillionSend.Client.t(), map()) ::
  {:ok, MillionSend.Contacts.Contact.t()} | {:error, MillionSend.Error.t()}

PATCH /contacts/:id_or_email. Include a key with nil to clear it; omit to leave unchanged.

update_topics(client \\ MillionSend.client(), params)

@spec update_topics(MillionSend.Client.t(), map()) ::
  {:ok, MillionSend.Contacts.Contact.t()} | {:error, MillionSend.Error.t()}

PATCH /contacts/:id_or_email/topics — set per-topic subscriptions. params carries the address plus topics: as a list of %{id: ..., subscription: :opt_in | :opt_out}.