ActiveCampaign agency partners have a powerful tool at their disposal: our Agency API allows you to create your own interface for managing your agency accounts. Combined with our standard API, this allows you to extend your own products and services to take advantage of agency-specific functionality.

This article will provide a brief tutorial on how to use our API to establish a simple interface for managing your agency accounts, which you can add to your own website or application.

We are going to demonstrate a step-by-step form that allows you to add new accounts, add a template for each account, and provide a link that logs-in the user automatically.


Custom Domain

This tutorial assumes you have your own custom domain that you use for each account. For example, let’s say your custom domain is:

For each account created, it will be assumed to map to a sub-domain of the above. For example:


Getting Started

We are providing the entire script that you can use on your own site. Feel free to download it and compare with it as we walk through things below.
Start by defining your custom domain, ActiveCampaign API URL, and API Key towards the top of the script:

$your_domain = "";
$reseller_api_url = "";
$reseller_api_key = "";

Agency partners can find their API URL and key in the partner administration interface:
Screenshot of reseller panel
Our HTML form (for the first step) will look like this:
Screenshot of the HTML form
When submitted, we first check if the account name exists, and if not, add the account:

$account_name = $_POST["account_name"];
// check if account name already exists
$name_exists = $ac->api("account/name_check?account={$account_name}");
if (!(int)$name_exists->success) {
  $alert = $name_exists->error;
else {
  // name is available. proceed with adding account.
  // add account
  $account = get_object_vars(json_decode('{
    "account": "' . $account_name . '",
    "cname": "' . $account_name . '.' . $your_domain . '",
    "name": "' . $client_name . '",
    "email": "' . $client_email . '",
    "notification": "' . $client_email . '",
    "plan": "' . $plan . '"
  $account = $ac->api("account/add", $account);

If adding the account is successful, it will inherit your default branding settings that you have set up. For example:
Screenshot of Reseller admin panel
Next, we’ll need to pause the script for a minute or two (sometimes it can take a few minutes to fully create an account in the system).


Then we can obtain that account’s API Key (so we can add data to the account on their behalf).

// obtain this account's API URL and key
$ac2 = new ActiveCampaign(ACTIVECAMPAIGN_URL, null, "admin",  $account->password);
$user_me = $ac2->api("user/me");
$_SESSION["account_api_url"] = $user_me->apiurl;
$_SESSION["account_api_key"] = $user_me->apikey;

Next we’ll add an email template to the system (so it is ready for your client to use immediately):
Screenshot of the HTML form
Here is the code to add the template:

// add template
$template = array(
  "name" => $name,
  "html" => htmlspecialchars($html),
  "template_scope" => "all",
$template = $ac->api("message/template_add", $template);

What we’ll also do is generate a log-in link that you can send to the user, which will log-in them in automatically. You can also share the username and password with them.

// get SSO link
$username = $_SESSION["username"];
$sso = $ac->api("auth/singlesignon?sso_user={$username}&sso_addr={$ip}&sso_duration=20");
$sso_url = $_SESSION["account_name"] . ".{$your_domain}/admin/main.php?_ssot={$sso->token}";

Screenshot of the HTML page
The user can log-in here with their username and password:

Or, using the automatic log-in link above will look something like this:

We also provide a sample email message that you could send to your user, informing them that their account was created, and containing useful links:

Again, grab our custom script and let us know if we can improve it, clarify anything, or help get this set up for you!