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:
- Who Loves You: Getting Open Rates Via The API This post only applies to Legacy Version 3 of...
- Washing With SOAP: Part 2 This post only applies to Legacy Version 3 of the...
- Washing With SOAP: Part 3 This post only applies to Legacy Version 3 of...
{ 0 comments… add one now }