Chapter 2. Interacting with the Address Book
Developers can create applications that add, edit and retrieve Address Book content by sending Requests to a specified URL. Address Book data is sent and received in the form of XML or JSON data structures. For more information, see Data Representation.
Searching the Address Book
The method searchContacts retrieves a subset of the
user's address book given a set of search criteria specified by URL
parameters. The general format of the response produced by the
searchContacts method is:
For example, the following request looks for the string "eva" inside all fields and all category names in a user's address book.
A typical response returned by the preceding
searchContacts request in JSON format is:
The same result returned in XML format:
Note
The searchContacts method is read-only; read access
must be granted by the user.
Parameters
The parameters of the searchContacts method fall
into four categories:
- Contact Criteria
Finds contacts in the address book.
- Display Criteria
Selects which fields will be returned by the search.
- Paging
Requests a smaller set of contacts from the returned result set.
- Bucketing
Requests a smaller set of contacts from the returned result set, bucketing sorts the results according to specified fields, and divides the results into buckets.
Multiple criteria are separated with an ampersand, '&'. For example, the following request will return the names, phone numbers and email addresses of contacts whose first name starts with "K".
Contact Criteria
The searchContacts method queries the address
book to find contacts that match a set of contact criteria on entries in the address book. Contact
criteria are specified by parameters in the following format:
fields.condition=values
Multiple contact criteria are "AND"ed together using "&". That is, a contact will match only if all criteria in the request matches. For example, to find all contacts in the address book with a phone number starting with "415" and first name starting with a "K", you could construct the following contact criteria:
Multiple fields and values specified in the criteria result in the "OR" of all field/value combinations. The following criteria will find contacts that have a phone number or an email address, or both:
When building the URL, you must adhere to the following guidelines:
- URL-encode each acceptable value. For example,
"Frédérique"becomes"Fr%C3%A9d%C3%A9rique". - Join values using ','. For example,
."a%2Cb,Fr%C3%A9d%C3%A9rique"Notice that the comma character appears in the URL as ',' when it separates values, but it appears as '%2C' when it is part of a value.
- Join the left hand side and the right hand side parts with
'='. For example
"name.last,name.first.contains=a%2Cb,Fr%C3%A9d%C3%A9rique" - At least one non-empty parameter must be specified or an error will be returned.
The following table describes the input that each parameter in the criteria accepts.
Table 2.1. Contact Criteria
| Parameter | Meaning |
|---|---|
fields
|
A comma-separated list of field, components or pseudo-fields. Criteria resulting from each element in the list are "OR"'ed
together. Each element in the list can be one of the following:
|
condition
|
One of the following condition keywords:
|
values
|
A comma-separated list of values to match against address book data. Criteria resulting from each value is "OR"ed together.
When present is used as condition, only "0" or "1" are valid values, without commas.
|
Criteria Types
Criteria are classified into four types: 1, 2, 3 and 4. The table below defines which conditions are of which "type":
Table 2.2. Criteria Types
| Type | Criteria |
|---|---|
| 1 |
present=1
|
| 2 |
present=0
|
| 3 | Contains one of the following condition keywords:
|
| 4 | cid.is= or cid.cs-is= (Criteria restricting the search to the specified Contact IDs.)
|
Contact Criteria Limitations
- You can search for the first, middle and last name components of a structured field, but no other components, such as ZIP code.
- You cannot search by field flag. For example, when searching for a phone, all kinds of phones will match (work, home, mobile). The application needs to make distinctions between field flags.
- You can combine contact criteria of the same type as long
as they do not have multiple field references. In other words,
you cannot combine "AND" and "OR" criteria of the same type. For
example,
is invalid because both criteria are type 1, and the first criteria specifies two fields, while
is valid.
The following table provides examples of valid and invalid combinations:
Table 2.3. Example Criteria Types
| Example Criteria | Valid or Invalid | Reason |
|---|---|---|
|
|
Invalid | Invalid because it is an AND of two criteria type "1", the first of which has multiple fields: phone and email. |
|
|
Valid | Valid because it is an AND of a criteria type "1" and "2". |
|
|
Invalid | Invalid because it is an AND of two type "3" criteria, the second one of which has multiple fields. |
|
|
Valid | Valid because it is an AND of two single field type "3" criteria. |
|
|
Valid | Valid because it is an AND of two single field type "3" criteria. |
cid.is=14,18,20
|
Valid | Valid, returns contacts with IDs 14, 18 and 20 if they exist. Non-existent contacts will not cause an error, they will be simply absent from the result. |
|
|
Valid | Valid, returns those contacts with Contact ID either 14, 18 or 20, which also have a phone field. If no contacts satisfy both conditions simultaneously, the result set will be empty. |
Display Criteria
The searchContacts method accepts parameters that
specify which fields are returned and how they will be displayed.
Display criteria are not coupled with contact criteria in any
way.
Specify display criteria using the following parameters:
Table 2.4. Display Criteria
| Parameter | Meaning |
|---|---|
fields
|
A comma-separated list of field types to return. If the fields parameter is omitted, all fields are returned. The list of
fields to return can also contain any combination of the following pseudo-field specifications:
|
sort-fields
|
A comma-separated list of Field Types specifying which fields to use for sorting. The first field in the list is the primary sort criteria; the second and subsequent fields are used to disambiguate. |
sort
|
Sort order: asc (default) for ascending; desc for descending.
|
The following sample request returns contacts whose first name starts with "K". Only contacts containing a phone number or an email address are returned. The names, phone numbers and email address of matching contacts are returned.
Paging
Paging is used to request a smaller set of contacts out of a larger result set. When paging is in effect, Address Book servers perform the search, sort the result according to sort fields (or the default sort criteria), and then extract a range from the sorted list of matches.
Table 2.5. Paging Parameters
| Parameter | Meaning |
|---|---|
page
|
Specifies the page number to return; 0 is the first page in the sort-order. |
pagesize
|
Specifies the number of contacts per page. |
If N is the total number of matching contacts, S is the page size and P is the requested page-number, the following (possibly empty, inclusive) range of matches will be returned:
P*S -- min(N,(P+1)*S-1)
When paging is in effect, the response entity will contain the
attribute total-matches: total number of matching
contacts, of which only a page is returned.
The following sample request returns the first page (with five contacts per page) of contacts whose first name starts with "K". Only contacts containing a phone number or an email address are returned. The names, phone numbers and email address of matching contacts are returned. Contacts are returned sorted by first name.
Sample response:
Bucketing
Bucketing is another way to request a subset of contacts out
of a larger result set. When bucketing is in effect, Address Book
servers perform the search, sort the result according to sort-fields
(or the default sort criteria), and split the result into buckets.
Contacts in one of these buckets, specified by bucket,
are returned in full and called the current bucket. For all other buckets, the first and the last
contact in the bucket is returned and called the bucket header (unless the header is disabled with
nobucketheader).
Table 2.6. Bucketing Parameters
| Parameter | Meaning |
|---|---|
bucket
|
The 0-based number of the bucket to return. 0 is the first bucket in the sort-order |
maxbucketsize
|
The preferred maximum number of contacts per bucket |
minbucketcount
|
The preferred minimum number of buckets |
nobucketheader
|
If 1, the bucket header will be omitted from the response |
When bucketing is in effect, the response has the following structure:
Table 2.7. Bucketing Response Items
| Value | Meaning |
|---|---|
total-matches
|
Total number of matching contacts |
buckets
|
The bucket header: summary of buckets other than the current bucket (bucket that is returned in full)
|
contacts
|
Contacts in the current bucket (bucket that is returned in full) |

