Subscribers

These code snippets demonstrate things you can do with Subscribers.
Check out our Getting Started guide if you're not sure how to use these.

Add/Create Subscribers

This code snippet demonstrates how to add Subscribers to a List.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
// Complete example on how to add a subscriber to your List.

// Refer to our getting started guide for a complete API walkthrough
// https://labs.aweber.com/getting_started/main

require_once('aweber_api/aweber_api.php');

$consumerKey    = '***'; # put your credentials here
$consumerSecret = '***'; # put your credentials here
$accessKey      = '***'; # put your credentials here
$accessSecret   = '***'; # put your credentials here
$account_id     = '***'; # put the Account ID here
$list_id        = '***'; # put the List ID here

$aweber = new AWeberAPI($consumerKey, $consumerSecret);

try {
    $account = $aweber->getAccount($accessKey, $accessSecret);
    $listURL = "/accounts/{$account_id}/lists/{$list_id}";
    $list = $account->loadFromUrl($listURL);

    # create a subscriber
    $params = array(
        'email' => 'johndoe@example.com',
        'ip_address' => '127.0.0.1',
        'ad_tracking' => 'client_lib_example',
        'misc_notes' => 'my cool app',
        'name' => 'John Doe',
        'custom_fields' => array(
            'Car' => 'Ferrari 599 GTB Fiorano',
            'Color' => 'Red',
        ),
        'tags' => array('cool_app', 'client_lib', 'other_tag'),
    );
    $subscribers = $list->subscribers;
    $new_subscriber = $subscribers->create($params);

    # success!
    print "A new subscriber was added to the $list->name list!";

} catch(AWeberAPIException $exc) {
    print "<h3>AWeberAPIException:</h3>";
    print " <li> Type: $exc->type              <br>";
    print " <li> Msg : $exc->message           <br>";
    print " <li> Docs: $exc->documentation_url <br>";
    print "<hr>";
    exit(1);
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""Python example to add a subscriber."""
from aweber_api import AWeberAPI, APIException

# Complete example on how to add a subscriber to your List.

# not sure where to find your keys?
# check out our authorization getting started guide
# https://labs.aweber.com/snippets/auth/getting_started

consumer_key = '****'     # replace with your real keys
consumer_secret = '****'  # replace with your real keys
access_key = '****'       # replace with your real keys
access_secret = '****'    # replace with your real keys
list_id = '****'          # replace with your list id

aweber = AWeberAPI(consumer_key, consumer_secret)

try:
    account = aweber.get_account(access_key, access_secret)
    list_url = '/accounts/%s/lists/%s' % (account.id, list_id)
    list_ = account.load_from_url(list_url)

    # create a subscriber
    params = {
        'email': 'johndoe@example.com',
        'ip_address': '127.0.0.1',
        'ad_tracking': 'client_lib_example',
        'misc_notes': 'my cool app',
        'name': 'John Doe',
        'custom_fields': {
            'Car': 'Ferrari 599 GTB Fiorano',
            'Color': 'Red',
        },
        'tags': ['cool_app', 'client_lib'],
    }
    subscribers = list_.subscribers
    new_subscriber = subscribers.create(**params)

    # success!
    print "A new subscriber was added to the %s list!" % (list_.name)

except APIException, exc:
    (exc_type, exc_msg) = str(exc).split(': ', 1)
    print '<h3>APIException:</h3>'
    print ' <li> Type: ' + exc_type
    print ' <li> Msg: ' + exc_msg
    print ' <li> Docs: ' + str(exc)
    print '<hr>'
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
require 'aweber'

oauth = AWeber::OAuth.new('consumer_key', 'consumer_secret')
oauth.authorize_with_access('your access token', 'your access secret')
aweber = AWeber::Base.new(oauth)

new_subscriber = {}
new_subscriber["email"] = "fake@example.com"
new_subscriber["name"] = "My New Subscriber"

aweber.account.lists.find_by_name("mylistname").subscribers.create(new_subscriber)

Update Subscriber Information

This code snippet demonstrates how to update Subscriber information.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
# Example on how to update a subscriber.

# Refer to our getting started guide for a complete API walkthrough
# https://labs.aweber.com/getting_started/main

try {
    $subscriber->name = 'John Doe';
    $subscriber->ad_tracking = 'BestCustomer';
    $subscriber->tags = array(
        'add' => array('new_tag'),
        'remove' => array('cool_app')
    )
    $subscriber->save();

    # get the new subscriber entry
    $updated_subscriber = $subscriber->loadFromUrl($subscriber->url);
    print "tags: ";
    print_r($updated_subscriber->data['tags']);
}

catch(AWeberAPIException $exc) {
    print "<h3>AWeberAPIException:</h3>";
    print " <li> Type: $exc->type              <br>";
    print " <li> Msg : $exc->message           <br>";
    print " <li> Docs: $exc->documentation_url <br>";
    print "<hr>";
} 
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# Example on how to update a subscriber.

# Refer to our getting started guide for a complete API walkthrough
# https://labs.aweber.com/getting_started/main

try:
    subscriber.name = 'John Doe'
    subscriber.ad_tracking = 'BestCustomer'
    subscriber.tags = {'add': ['new_tag'], 'remove': ['cool_app']}
    subscriber.save()

    updated_subscriber = subscriber.load_from_url(subscriber.url)
    print 'Updated tags: ', updated_subscriber.tags

except APIException, exc:
    (exc_type, exc_msg) = str(exc).split(': ', 1)
    print '<h3>APIException:</h3>'
    print ' <li> Type: ' + exc_type
    print ' <li> Msg: ' + exc_msg
    print ' <li> Docs: ' + str(exc)
    print '<hr>'

Search for on all Lists

This code snippet demonstrates how to seach for Subscribers on any List.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
# Example on how to find all subscribers on any list that are subscribed.

# Refer to our getting started guide for a complete API walkthrough
# https://labs.aweber.com/getting_started/main

try {
    $params = array('status' => 'subscribed');
    $found_subscribers = $account->findSubscribers($params);
    foreach($found_subscribers as $subscriber) {
        echo $subscriber->email . "\n";
    }
}

catch(AWeberAPIException $exc) {
    print "<h3>AWeberAPIException:</h3>";
    print " <li> Type: $exc->type              <br>";
    print " <li> Msg : $exc->message           <br>";
    print " <li> Docs: $exc->documentation_url <br>";
    print "<hr>";
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Example on how to find all subscribers on any List that are subscribed.

from aweber_api import AWeberAPI, APIException

# not sure where to find your keys?
# check out our authorization getting started guide
# https://labs.aweber.com/snippets/auth/getting_started

consumer_key = '****'     # replace with your real keys
consumer_secret = '****'  # replace with your real keys
access_key = '****'       # replace with your real keys
access_secret = '****'    # replace with your real keys

aweber = AWeberAPI(consumer_key, consumer_secret)

try:
    account = aweber.get_account(access_key, access_secret)

    found_subscribers = account.findSubscribers(status='subscribed')
    for subscriber in found_subscribers:
        print subscriber.email

except APIException, exc:
    (exc_type, exc_msg) = str(exc).split(': ', 1)
    print '<h3>APIException:</h3>'
    print ' <li> Type: ' + exc_type
    print ' <li> Msg: ' + exc_msg
    print ' <li> Docs: ' + str(exc)
    print '<hr>'

Search for on Single List

This code snippet demonstrates how to search for a Subscribers on a single List.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
# Example on how to find all subscribers on a single List that are subscribed.

# Refer to our getting started guide for a complete API walkthrough
# https://labs.aweber.com/getting_started/main

try {
    $params = array('status' => 'subscribed');
    $found_subscribers = $subscribers->find($params);
    foreach($found_subscribers as $subscriber) {
        echo $subscriber->email . "\n";
    }
}

catch(AWeberAPIException $exc) {
    print "<h3>AWeberAPIException:</h3>";
    print " <li> Type: $exc->type              <br>";
    print " <li> Msg : $exc->message           <br>";
    print " <li> Docs: $exc->documentation_url <br>";
    print "<hr>";
}
 
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# Example on how to find all subscribers on a single List that are subscribed.

# Refer to our getting started guide for a complete API walkthrough
# https://labs.aweber.com/getting_started/main

try:
    found_subscribers = subscribers.find(status='subscribed')
    for subscriber in found_subscribers:
        print subscriber.email

except APIException, exc:
    (exc_type, exc_msg) = str(exc).split(': ', 1)
    print '<h3>APIException:</h3>'
    print ' <li> Type: ' + exc_type
    print ' <li> Msg: ' + exc_msg
    print ' <li> Docs: ' + str(exc)
    print '<hr>'

Move Subscribers

This code snippet demonstrates how to move Subscribers from one List to another List.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
# Example on how to move a subscriber to a new list.
# This subscriber will get moved and start receiving followups.

# Refer to our getting started guide for a complete API walkthrough
# https://labs.aweber.com/getting_started/main

try {
    # search for a list called 'my_other_list'
    $found_lists = $account->lists->find(array('name' => 'my_other_list'));
    $destination_list = $found_lists[0];

    # move the subscriber over to 'my_other_list'
    $subscriber->move($destination_list);
}

catch(AWeberAPIException $exc) {
    print "<h3>AWeberAPIException:</h3>";
    print " <li> Type: $exc->type              <br>";
    print " <li> Msg : $exc->message           <br>";
    print " <li> Docs: $exc->documentation_url <br>";
    print "<hr>";
}
 
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# Example on how to move a subscriber to a new list.
# This subscriber will get moved and start receiving followups.

# Refer to our getting started guide for a complete API walkthrough
# https://labs.aweber.com/getting_started/main

try:
    # search for a list called 'my_other_list'
    found_lists = account.lists.find(name='my_other_list')
    destination_list = found_lists[0]

    # move the subscriber over to 'my_other_list'
    subscriber.move(destination_list)

except APIException, exc:
    (exc_type, exc_msg) = str(exc).split(': ', 1)
    print '<h3>APIException:</h3>'
    print ' <li> Type: ' + exc_type
    print ' <li> Msg: ' + exc_msg
    print ' <li> Docs: ' + str(exc)
    print '<hr>'

Move & Send No Followups

This code snippet demonstrates how to move Subscribers from one List to another List including
a numeric value to apply the last followup message number sent on the new list.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
# Example on how to move a subscriber to a new list.
# This subscriber will get moved and will not receive any followup messages.

# Refer to our getting started guide for a complete API walkthrough
# https://labs.aweber.com/getting_started/main

try {
    # search for a list called 'my_other_list'
    $found_lists = $account->lists->find(array('name' => 'my_other_list'));
    $destination_list = $found_lists[0];

    # move the subscriber over to 'my_other_list' and set them at the end of
    # the followup sequence
    $subscriber->move($destination_list, 1001);

    # Want to know why we set the last message number sent to 1001?
    # https://help.aweber.com/entries/21739966-why-does-it-say-1001-under-the-last-message-column-for-some-subscribers
}

catch(AWeberAPIException $exc) {
    print "<h3>AWeberAPIException:</h3>";
    print " <li> Type: $exc->type              <br>";
    print " <li> Msg : $exc->message           <br>";
    print " <li> Docs: $exc->documentation_url <br>";
    print "<hr>";
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Example on how to move a subscriber to a new list.
# This subscriber will get moved and will not receive any followup messages.

# Refer to our getting started guide for a complete API walkthrough
# https://labs.aweber.com/getting_started/main


try:
    # search for a list called 'my_other_list'
    found_lists = account.lists.find(name='my_other_list')
    destination_list = found_lists[0]

    # move the subscriber over to 'my_other_list' and set them at the end of
    # the followup sequence
    subscriber.move(destination_list, last_followup_message_number_sent=1001)

    # Want to know why we set the last message number sent to 1001?
    # https://help.aweber.com/entries/21739966-why-does-it-say-1001-under-the-last-message-column-for-some-subscribers

except APIException, exc:
    (exc_type, exc_msg) = str(exc).split(': ', 1)
    print '<h3>APIException:</h3>'
    print ' <li> Type: ' + exc_type
    print ' <li> Msg: ' + exc_msg
    print ' <li> Docs: ' + str(exc)
    print '<hr>'

Delete Subscribers

This code snippet demonstrates how to delete Subscribers from Lists.
Use this when you want to remove all details about the subscriber (including analytics activity).
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
<?php
# Example on how to delete a subscriber.

# Refer to our getting started guide for a complete API walkthrough
# https://labs.aweber.com/getting_started/main

try {
    $subscriber->delete();
}

catch(AWeberAPIException $exc) {
    print "<h3>AWeberAPIException:</h3>";
    print " <li> Type: $exc->type              <br>";
    print " <li> Msg : $exc->message           <br>";
    print " <li> Docs: $exc->documentation_url <br>";
    print "<hr>";
}
 
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
from aweber_api import APIException

# Example on how to delete a subscriber.

# Refer to our getting started guide for a complete API walkthrough
# https://labs.aweber.com/getting_started/main

try:
    subscriber.delete()

except APIException, exc:
    (exc_type, exc_msg) = str(exc).split(': ', 1)
    print '<h3>APIException:</h3>'
    print ' <li> Type: ' + exc_type
    print ' <li> Msg: ' + exc_msg
    print ' <li> Docs: ' + str(exc)
    print '<hr>'

Get Analytics Activity

This code snippet demonstrates how to retrieve analytics activities for a specific Subscriber.
(messages they opened, links they clicked, when they subscribed, etc)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
# Example on how to find subscriber activity for a single Subscriber

# Refer to our getting started guide for a complete API walkthrough
# https://labs.aweber.com/getting_started/main

try {
    $subscriber_activity = $subscriber->getActivity();
    foreach($subscriber_activity as $event) {
        echo $event->self_link . "\n";
    }
}

catch(AWeberAPIException $exc) {
    print "<h3>AWeberAPIException:</h3>";
    print " <li> Type: $exc->type              <br>";
    print " <li> Msg : $exc->message           <br>";
    print " <li> Docs: $exc->documentation_url <br>";
    print "<hr>";
}
  
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# Example on how to find subscriber activity for a single Subscriber

# Refer to our getting started guide for a complete API walkthrough
# https://labs.aweber.com/getting_started/main

try:
    subscriber_activity = subscriber.get_activity()
    for event in subscriber_activity:
        print event.self_link

except APIException, exc:
    (exc_type, exc_msg) = str(exc).split(': ', 1)
    print '<h3>APIException:</h3>'
    print ' <li> Type: ' + exc_type
    print ' <li> Msg: ' + exc_msg
    print ' <li> Docs: ' + str(exc)
    print '<hr>'