akifquddus
akifquddus

Reputation: 632

Retrieve All User Lists using Aweber API

I am adding AWeber as an autoresponder in a web application. Using AWeber API, I am able to add a new subscriber to list with a known name which is in this case is firstlist:

$app = new MyApp();
$app->findSubscriber('[email protected]');
$list = $app->findList('firstlist');
$subscriber = array(
'email' => '[email protected]',
'name'  => 'Name here'
);
$app->addSubscriber($subscriber, $list);

Function definition for findList() is:

function findList($listName) {
    try {
        $foundLists = $this->account->lists->find(array('name' => $listName));
        return $foundLists[0];
    }
    catch(Exception $exc) {
        print $exc;
    }
}

As I am developing a public application, so I need to provide users an option to select from their available lists. Please guide me how I can retrieve all the lists name.

Upvotes: 0

Views: 981

Answers (2)

Clifton Hatfield
Clifton Hatfield

Reputation: 71

In short, I pulled the lists by first finding the Aweber User Id so that I could use it in the URL https://api.aweber.com/1.0/accounts/<id>/lists

To find the User ID, I first got the account.

$this->aweber->getAccount($token['access'], $token['secret']);

Then, I retrieve the user's information.

$aweber_user = $this->aweber->loadFromUrl('https://api.aweber.com/1.0/accounts');

From that, I grabbed the user ID with...

$id = $aweber_user->data['entries'][0]['id'];

Once I had the user ID, I could then retrieve their lists with...

$lists = $this->aweber->loadFromUrl('https://api.aweber.com/1.0/accounts/'.$id.'/lists');

This example is more of a procedural approach, of course, I recommend utilizing classes.

Upvotes: 0

Zahid Usman Cheema
Zahid Usman Cheema

Reputation: 198

You are returning $foundLists[0] so it will return single list. Try to return foundLists and check what it returns. This may help you: https://labs.aweber.com/snippets/lists

Upvotes: 1

Related Questions