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

Relationship 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.

Relationship API

civicrm_relationship_create(&$params )

Availability: 1.8v

Creates a new relationship between two contacts, and returns the newly created relationship object. CRM includes a default set of reserved relationship types (e.g. 'Household Member, "Employee", "Parent", etc.) - and supports creation of custom relationship types.

By convention, 'contact_a' is the subject, and the 'contact_b' is the object of the relationship. For example, Jane Stein ('contact_a') is a 'Household Member' ('relationship_type') of 'The Stein Family' ('contact_b' whose contact_type is 'Household').

The relationship_type is a relationship type string reserved relationship types .
For example: 'Employee of', 'Spouse of'.

A 'duplicate relationship' error is returned if there is already of relationship of the specified type between the two contacts. An error is also returned if either contact is invalid, or the specified relationship_type is not applicable to the type(s) of the Contacts.

Parameters:

  • 'params' (array) Associative array of property name/value pairs to be inserted. See Data Model for available properties.
  • for updating relationship record pass relationship id in array like $params['id']

Returns:

  • (array) id of created Relationship on success, error message otherwise.

    Use Existing Relationship Types When Possible

    In many cases, CRM data will be shared between modules. Using the reserved (default) relationship types will facilitate meaningful sharing of data.
    If you find the need for a type that doesn't already exist, use civicrm_relationship_type_add to create custom relationship types.



    Create Relationship
    Result

civicrm_contact_relationship_get($params_contact_a, $params_contact_b = NULL, $relationship_type_name = array(), $sort = NULL)

Availability: 1.8v

Returns array of contacts related to contact_a. If contact_b is passed, only relationships between the two contacts are returned.

NOTE: CRM will evaluate and retrieve relationships betweeen Contact a and Contact b regardless of whether they occupy the 'A' or 'B' slot in the Relationship object.

If 'relationship_type' is specified as an array of strings, relationship(s) returned are limited to those of the specified type. Otherwise all related contacts are returned. Use 'return_properties' to constrain the contact properties included in the returned Contact object(s).

Parameters:

  • params' (array) Associative array of property name/value pairs to be inserted.

Returns:

  • Array of Relationships with id
  • Null (if there are no applicable related contacts).
    Get Relationships
    Result

civicrm_relationship_get(&$params)

Gets all the relationship(s) for a specified contact. This function is a simple wrapper to civicrm_contact_relationship_get

Parameters:

  • array containing contact id

Returns:

  • array of contacts related to contact_a if successful, error message otherwise

civicrm_relationship_delete(&$params)

Availability: 1.8v

Deletes the specified relationship

Parameters:

  • array containing relationship id

Returns:

  • success message if successful, error message otherwise
    Delete Relationship
    Result

civicrm_relationship_type_add($params)

Availability: 1.2v

Adds a new relationship_type definition for a specified contact type. See Data Model for required values for the 'Relationship_type'.

Parameters:

  • 'params' (array) Associative array of property name/value pairs to insert in new relationship type.

Returns:

  • Newly created Relationship_type array
    Relationship type add
    Result

civicrm_relationship_type_delete()

Availability: 1.8v

Deletes the specified relationship type

Parameters:

  • Parameters:
  • array containing relationship id

Returns:

  • success message if successful, error message otherwise
    Delete Relationship Type
    Result

civicrm_relationship_types_get()

Availability: 1.8v

Returns array of relationship Type related to passing agrument. If array is empty, then all relationship Type returned in array.

Returns:

  • Array of Relationships Type with id and other info
  • Null (if there are no applicable related contacts).
    Get Relationship Type
    Result
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.