This documentation relates to CiviCRM version 3.2. It's not maintained anymore.
Current version of documentation.

Contact APIs

Skip to end of metadata
Go to start of metadata

This page refers to outdated version of CiviCRM. Check current version of documentation.


Documentation Search


CiviCRM 3.2 Documentation

Support and Participation

Developer Resources


CiviCRM book!

Make sure to check out Understanding CiviCRM as well! You can also support this project by ordering a hard copy.

Note: although the contact api can be used to retrieve location information (e.g. postal address, email addres, etc.) you should use the location API to create and update location information.

Contact APIs (Individuals, Households and Organizations)

civicrm_contact_create( &$params )

Availability: v2.2.3

Add a contact. If 'dupe_check' is set to true in $params array, then dupe checking will be done while creating the contact

(In earlier versions than 2.2.3, use civicrm_contact_add).

Parameters:

  • 'params' (array) Associative array of property name/value pairs

Returns:

  • On success, returns array containing created contact id
  • On failure, returns array containing error_message
Warning
  • contact_type must be passed as a paramater when creating a contact.
Creating a Contact
Result

civicrm_contact_update( &$params )

Availability: v2.2.3

Update a contact.

(In earlier versions than 2.2.3, use civicrm_contact_add with a contact_id).

Parameters:

  • 'params' (array) Associative array of property name/value pairs

Returns:

  • On success, returns array containing updated contact id
  • On failure, returns array containing error_message
Warning
  • contact_type must be passed as a paramater when updating a contact.
  • contact_id must be passed as a paramater when updating a contact.


Updating a Contact


Result


civicrm_contact_get( &$params )

Get = Search

Availability: v1.8 and later

The GET API can get one or more contact's details & is the recommended API for searching

Returns an array of contacts using the contact_id as the array key .

The $params can contain the following parameters any of the parameters that would be retrieved using contact get

An empty array is returned if there is no match. Do print_r on the returned value from the example below to examine the array and properties returned in your site.

Please note: you can use a custom field to get details of a contact too. You need to find the ID for your specific custom field in the table civicrm_custom_field.

If the ID of the custom field is for example 9, you can use custom_9 (so $params = array('custom_9' => '345678' and then $retrieved = &civicrm_contact_get( $params).

Parameters:

  • 'params' (array) Associative array (name/value pairs) of id to attempt to match on. Refer to the CiviCRM schema files and the CiviCRM ERD 2.0 for more details on properties for each type of contact.

Returns:

  • Contact array with all available properties
Example: civicrm_contact_get( )
Result

How to add contact's website in a query:

In CiviCRM 3.2 websites (previously home_URL) have their own table in database which makes possible to have multiple websites per contact. Therefore the API has changed a bit. Now you have to define website as an array and you will get an array as well.

Example: civicrm_contact_get( )
Result

How To Retrieve Custom Fields:

It is possible to retrieve specific fields (both standard contact fields and custom contact fields) using the following param structure where N is the field id of the custom field in the civicrm_custom_field table. You can specify as many fields as you want in the params array:

Example: civicrm_contact_get( )
Result

civicrm_contact_delete( &$params )

Availability: v1.8

Deletes the specified contact.

Parameters:

  • 'params' (array) A valid (name/value pair) Contact of contact_id (passed by reference).

Returns:

  • true if success, else false
  • An error if 'contact' is invalid, permissions are insufficient, etc.
Example: civicrm_contact_delete( )

civicrm_contact_search( &$params ) - DEPRECATED

Availability: v1.8
Retrieve a set of contacts, given a set of input params

You should use the get api

Parameters:

  • 'params' (array) Associative array of name-value pair
  • return properties are also passed in the params array. All the return properties should be prefixed with 'return.'. If array( 'return.home_url' => 1 ) will be passed then returned result will have only home_url values for the searched contacts

Note: As of 2.x API, civicrm_contact_search() will enforce a 25 contact limit on number of contacts returned. If you want to return more than 25 contacts, add "rowCount" => XXXX to your $params array, where XXXX is the top limit on number of contacts you want returned.

Returns:

  • Array of contacts,if success
  • Array with an error id and error message,if fails.
Example: civicrm_contact_search( )
Result

Sort and Paging:

Example: sorting and paging

civicrm_contact_search_count( &$params )

Availability: v1.8
Returns the number of Contact objects which match the search criteria specified in $params.
Parameters:

  • 'params' (array) Associative array of name-value pair

Returns:

  • int no of contacts,if success
Example: civicrm_contact_search( )
Labels
  • None

Creative Commons License
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-Share Alike 3.0 United States Licence.