countAccounts

Counts the number of Accounts that match the search criteria.

countAccounts

Counts the number of Accounts that match the search criteria.

Top ↑

Syntax

int countAccounts(
    string api_key,
  [ array search_criteria,
    bool include_sub_accounts ] 
);

Parameters

api_key (string)

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

search_criteria (array - optional)

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

include_sub_accounts (bool - optional)

Value that indicates whether you want to search within sub-Accounts. Valid values are:

  • true - Search within sub-Accounts.
  • false - Do not search within sub-Accounts.

Return Value

The number of Accounts that match the search criteria.

Examples

Since multiple search criteria are ANDed, the following code counts the number of Accounts in Australia with the word idea in the company name.

$api = new Api($url, 'YOURAPIKEY');

$criteria = array(
    array(
        'field' => 'company_name',
        'modifier' => 'contains',
        'value' => 'idea'
    ),
    array(
        'field' => 'company_country',
        'modifier' => 'exactly',
        'value' => 'Australia'
    )
);

$include_sub_accounts = false;

$result = $api->invokeMethod('searchAccounts', $criteria, $include_sub_accounts));
{
    "id": 1,
    "method": "countAccounts",
    "params": [
        "YOURAPIKEY",
        [
            {
                "field": "company_name",
                "modifier": "contains",
                "value": "idea"
            },
            {
                "field": "company_country",
                "modifier": "exactly",
                "value": "Australia"
            }
        ],
        false
    ]
}
{
    "id": 1,
    "result": 23,
    "error": null
}

Error Codes

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

Code Error Description
302 Undefined Method Error Searching has failed for some reason. Please try again later.
310 Invalid Method Parameters One or more of the parameters you have passed are invalid.
311 Invalid Search Parameter Format The searching criteria you have entered is invalid.
321 Administrative access denied You do not have access to this method.

See Also