countContacts

Counts the number of Contacts in a List that match the search criteria.

countContacts

Counts the number of Contacts in a List that match the search criteria.

Top ↑

Syntax

int countContacts(
    string api_key,
    int list_id,
  [ array search_criteria ] 
);

Parameters

api_key (string)

The key required to access the API. See Getting Started for more information.

list_id (int)

The ID of the List of Contacts to count.

search_criteria (array - optional)

An array of search criteria that selects the Contacts to be counted. See searchContacts for a description of the values that can be searched on.

Return Value

The number of Contacts in the List that match the search criteria.

Examples

The example code uses countContacts to find the total number of Contacts in a List who are unsubscribed or deactivated:

$list_id = 1234567;     // can be obtained using searchLists()

$search_criteria = array(
    array('is_unsubscribed', 'exactly', 1),
    'OR',
    array('is_active', 'exactly', 0)
);

$api = new Api($url, 'YOURAPIKEY');
$contact_count = $api->invokeMethod('countContacts', $list_id, $search_criteria);
{
    "id": 1,
    "method": "countContacts",
    "params": [
        "YOURAPIKEY",
        1234567,
        [
            ["is_unsubscribed", "exactly", 1],
            "OR",
            ["is_active", "exactly", 0]
        ]
    ]
}
{
    "id": 1,
    "result": 23,
    "error": null
}

Remarks

Use getListById or searchLists to determine the total number of Contacts in a List.

Error Codes

This method may return the following error codes in addition to the standard error codes:

Code Error Description
303 Unable to Load List list_id is not a valid List
311 Invalid Search Parameter Format search_critera is not valid

See Also