ExCampaignMonitor v0.9.0 ExCampaignMonitor View Source
A wrapper for the Campaign Monitor JSON API
- Install the package by adding
ex_campaign_monitor
to your list of dependencies inmix.exs
:
def deps do
[
{:ex_campaign_monitor, "~> 0.2"}
]
end
- 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",
- 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
Create a webhook for a 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
Activate a specific webhook, via the webhook’s ID
ExCampaignMonitor.activate_webhook("a1a1a1a1", "webhook-b1b1b1b1")
> :ok
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"}}
Create a webhook for a list
ExCampaignMonitor.create_webhook("a1a1a1a1", ["Subscribe"], "http://mywebsite.com/subscribe", "json")
> {:ok, "webhook_id-982u981u298u298u2e9u289e"}
Delete a webhook by webhook_id
ExCampaignMonitor.delete_webhook("a1a1a1a1", "webhook_id-982u981u298u298u2e9u289e")
> {:ok, :webhook_deleted}
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"}}
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"}}
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"
}
]
}
Remove (delete) a single subscriber from your list
ExCampaignMonitor.remove_subscriber("person@domain.com")
> {:ok, :removed}
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}
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"}}