The extent to which the AWeber API is not clearly documented cannot be underscored enough (nor do their example scripts work very well). The below script was written so I could subscribe one user to multiple lists selected from a form.
Anyway, this script works when the subscribers->create method is commented out. I'm able to see my separate list ids feed to the list urls and then the list array data is fetched and returned. But once the create method is added back in, it only does one trip through the loop, subscribes the email parameter to the first list it finds and then the script stops:
<!DOCTYPE html>
<html>
<body>
<?php
require_once('aweber_api/aweber_api.php');
require_once('aweber_api/aweber_creds.php');
print "----<br>";
$aweber->adapter->debug = true;
print "----<br>";
//call the api key...
$aweber = new AWeberAPI($consumerKey, $consumerSecret);
$account = $aweber->getAccount($accessKey, $accessSecret);
$feeds = array_values($_GET);
//print form array
print "FORM ARRAY ";
print_r ($feeds);
echo "--<br>";
foreach($feeds[1] as $feed){
echo "--<br>";
try {
print "<br> Feed : $feed";
$listURL = "/accounts/{$account_id}/lists/{$feed}";
$list = $account->loadFromUrl($listURL);
$lists = $account->lists->find(array('name' => $listName));
print_r ($list);
print "<br><br><br>";
# create a subscriber
$params = array(
'email' => $feeds[0],
);
$subscribers = $list->subscribers;
$new_subscriber = $subscribers->create($params);
print "HERE " . $new_subscriber->email;
# success!
print "$new_subscriber->email 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>";
}
}
?>
</body>
</html>
And for the sake of context, here are some form parameters being passed into this script:
somehostnamehere.com/phptest/aweber_api/hltmt_addsubsv1.php?email=user22344%40gmail.com&aweber_list%5B%5D=2531241&aweber_list%5B%5D=2531242&aweber_list%5B%5D=2531243&aweber_list%5B%5D=2531244