A elixir middleware library for interfacing with the ActiveCampaign API.
The package can be installed by adding ex_activecampaign
to your list of dependencies in mix.exs
:
def deps do
[
{:ex_activecampaign, github: "piratestudios/ex_activecampaign"}
]
end
Once added, run mix deps.get
You will need to set the following configuration variables in your
config/config.exs
file:
use Mix.Config
config :ex_activecampaign, base_url: "https://<your-account>.api-us1.com/api/3",
api_token: "YOUR-ACTIVECAMPAIGN-TOKEN"
If you want to use different ActiveCampaign credentials for different environments, then create separate Mix
configuration files for each environment. To do this, change config/config.exs
to look like this:
# config/config.exs
use Mix.Config
# shared configuration for all environments here ...
import_config "#{Mix.env}.exs"
Then, create a config/#{environment_name}.exs
file for each environment. You can then set the
config :ex_activecampaign
variables differently in each file.
To use the middleware, simply add a call to the desired API method in the relevant part of the dependent codebase, e.g.:
def subscribe_to_mailing_list(email, first_name, last_name, phone) do
%{contact: %{id: id}} = ExActivecampaign.Contact.create_or_update(
%{"email" => email, "firstName" => first_name, "lastName" => last_name, "phone" => phone}
)
ExActivecampaign.Contact.update_list_status(
%{contact: id, list: 1, status: 1}
)
end
ExActivecampaign currently supports requests to the following endpoints of the ActiveCampaign API
- Create a contact -
ExActiveCampaign.Contact.create()
- Create or update contact -
ExActiveCampaign.Contact.create_or_update()
- Retrieve a contact -
ExActiveCampaign.Contact.retrieve()
- Update list status for a contact -
ExActiveCampaign.Contact.update_list_status()
- Retrieve a list -
ExActiveCampaign.List.retrieve()