This post only applies to Legacy Version 3 of the API
Did you know we had a function in our API to clear all contacts from a list? It was recently added and is conveniently called clearLists. This function will remove the contacts from a list, but it will not remove the contacts themselves from Bronto.
Here are a couple sample PHP functions that make use of the readLists and clearLists functions. With these functions you can clear one or more lists of all contacts, without having to individually remove contacts from the lists.
/**
* clear one or more lists of all contacts
*
* $bapi Binding to the Bronto API
* $lists Array of list ids
*
* returns an array of results
*/
function clear_lists($bapi, $lists)
{
$parameters = array("ids"=>$lists);
$results = $bapi->clearLists($parameters);
return($results->return->result);
}
/**
* get the ids for a set of list names
*
* $bapi Binding to the Bronto API
* $list_names The name of the lists to read
*
* returns an array of ids
*/
function get_list_ids($bapi, $list_names)
{
$list_ids = array();
// get all the lists
$attributes = array();
$attributes["label"] = FALSE;
$attributes["activeCount"] = FALSE;
$filter = array();
$parameters = array(“attributes”=>$attributes, “filter”=>$filter);
$results = $bapi->readLists($parameters);
// get ids for lists specified in $list_names
$lists = $results->return->lists;
foreach($lists as $list)
{
if(in_array($list->name, $list_names))
{
$list_ids[] = $list->id;
}
}
return($list_ids);
}
Alex Durzy
Support Engineer at Bronto
Related posts:
- Clear that List using the API v4 Last fall, Alex explained how to Clear Contacts From...
- The Pluses And Minuses Of List Management What happened to all my lists?!?!? You might be asking...
- Welcome Friend! Adding New Contacts Using the API This post only applies to Legacy Version 3 of...
{ 1 trackback }
{ 0 comments… add one now }