Spring Cleaning: Clearing Contacts From Lists

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

Comments

Clear that List using the API v4

[...] fall, Alex explained

[...] fall, Alex explained how to Clear Contacts From Lists in v3 of the API. You now have the same ability in v4 API using the clearLists function. All you [...]

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>

More information about formatting options

CAPTCHA
Just checking to see if you're a human visitor. We don't like automated spam submissions.