Manage Your Reseller Accounts with our API

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

This article will provide a brief tutorial on how to use our API to establish a simple interface for managing your reseller 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.

Requirements

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:

yourdomain.com

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

  • yourclient1.yourdomain.com
  • yourclient2.yourdomain.com

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 reseller URL, and API Key towards the top of the script:

<?php

$your_domain = "yourdomain.com";
$reseller_api_url = "https://www.activecampaign.com";
$reseller_api_key = "";

?>

Resellers can find their API URL and key in the reseller 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).

sleep(120);

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"];
$ip = $_SERVER["REMOTE_ADDR"];
$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:

http://yourclient1.yourdomain.com/admin/

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

http://yourclient1.yourdomain.com/admin/main.php?_ssot=e09d6dc6df3bf91fe2b2f663cc8d0b2a

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!

A trial is worth a thousand words.

Get started today, no credit card required.