ExCampaignMonitor v0.9.0 ExCampaignMonitor View Source

A wrapper for the Campaign Monitor JSON API

  1. Install the package by adding ex_campaign_monitor to your list of dependencies in mix.exs:
def deps do
  [
    {:ex_campaign_monitor, "~> 0.2"}
  ]
end
  1. Add your Campaign Monitor account API key and a List ID to your application’s config:
  config :ex_campaign_monitor,
    :api_key, "YOUR_API_KEY",
    :list_id, "YOUR_LIST_ID",
  1. Call a function on the ExCampaignMonitor module, for example:
defmodule MyApp.PageController do
  use MyAppWeb, :controller

  def index(conn, params) do
    ExCampaignMonitor.add_subscriber(%{
      email: params["email"], # email address of the user you want to subscribe
      consent_to_track: "Yes" # https://help.campaignmonitor.com/consent-to-track
    })
    send_resp(conn, "Subscriber added")
  end
end

Link to this section Summary

Functions

Activate a specific webhook, via the webhook’s ID

Add a new subscriber to your list

Create a new list

Delete a webhook by webhook_id

Get active subscribers for a list

Get details for a List by ID

Get a single subscriber by their email address

Import many subscribers to your list

List all webhooks created for the list ID provided

Remove (delete) a single subscriber from your list

Send a transactional smart email

Unsubscribe someone who is currently subscribed to your list

Update an existing subscriber from your list

Link to this section Functions

Link to this function activate_webhook(list_id, webhook_id) View Source

Activate a specific webhook, via the webhook’s ID

ExCampaignMonitor.activate_webhook("a1a1a1a1", "webhook-b1b1b1b1")
> :ok
Link to this function add_subscriber(subscriber) View Source

Add a new subscriber to your list

ExCampaignMonitor.add_subscriber(%{email: "someone@domain.com", consent_to_track: "Yes"})
> {:ok, %Subscriber{email: "someone@domain", consent_to_track: "Yes"}}

Create a new list

ExCampaignMonitor.create_list(%{title: "my list"})
> {:ok, %List{title: "my list"}}
Link to this function create_webhook(list_id, events, url, payload_format \\ "json") View Source

Create a webhook for a list

ExCampaignMonitor.create_webhook("a1a1a1a1", ["Subscribe"], "http://mywebsite.com/subscribe", "json")
> {:ok, "webhook_id-982u981u298u298u2e9u289e"}
Link to this function delete_webhook(list_id, webhook_id) View Source

Delete a webhook by webhook_id

ExCampaignMonitor.delete_webhook("a1a1a1a1", "webhook_id-982u981u298u298u2e9u289e")
> {:ok, :webhook_deleted}
Link to this function get_active_subscribers(list_id) View Source

Get active subscribers for a list

ExCampaignMonitor.get_active_subscribers("a1a1a1a1")
> {:ok, %List{list_id: "a1a1a1a1"}, subscribers: [%Subscriber{status: "active"}]}

Get details for a List by ID

ExCampaignMonitor.get_list_by_id("a1a1a1a1")
> {:ok, %List{title: "my list", list_id: "a1a1a1a1"}}
Link to this function get_subscriber_by_email(email) View Source

Get a single subscriber by their email address

ExCampaignMonitor.get_subscriber_by_email("person@domain.com")
> {:ok, %Subscriber{email: "person@domain.com", consent_to_track: "Yes"}}
Link to this function import_subscribers(subscribers) View Source

Import many subscribers to your list

ExCampaignMonitor.import_subscribers([
  %{
    email: "someone@domain.com",
    consent_to_track: "Yes"
  },
  %{
    email: "person@domain.com",
    consent_to_track: "No"
  }
])
> {:ok, 2}

List all webhooks created for the list ID provided.

ExCampaignMonitor.list_webhooks("a1a1a1a1")
> {:ok, [
    %{
      "WebhookID": "ee1b3864e5ca61618q98su98qsu9q",
      "Events": [
          "Subscribe"
      ],
      "Url": "http://example.com/subscribe",
      "Status": "Active",
      "PayloadFormat": "Json"
    }
  ]
}
Link to this function remove_subscriber(subscriber) View Source

Remove (delete) a single subscriber from your list

ExCampaignMonitor.remove_subscriber("person@domain.com")
> {:ok, :removed}
Link to this function send_smart_email(smart_email_id, data) View Source

Send a transactional smart email

ExCampaignMonitor.send_smart_email("a1a1a1a1", %{
  to: ["jack@jackmarchant.com"],
  data: %{new_password_url: "https://mywebapp.com/newpwd?uid=jguf45h74gf"}
})

Unsubscribe someone who is currently subscribed to your list

ExCampaignMonitor.unsubscribe("person@domain.com")
> {:ok, :unsubscribed}
Link to this function update_subscriber(subscriber) View Source

Update an existing subscriber from your list

ExCampaignMonitor.update_subscriber(%{
  old_email: "someone@domain.com",
  new_email: "person@domain.com",
  consent_to_track: "Yes"
})
> {:ok, %Subscriber{email: "person@domain.com", consent_to_track: "Yes"}}