3 * Test Generated example of using contact create API
4 * /*this demonstrates the usage of chained api functions. Specifically it has one 'parent function' &
5 2 child functions - one receives values from the parent (Contact) and the other child (Tag). *
7 function contact_create_example(){
9 'display_name' => 'batman',
10 'contact_type' => 'Individual',
11 'api.tag.create' => array(
12 'name' => '$value.id',
13 'description' => '$value.display_name',
14 'format.only_id' => 1,
16 'api.entity_tag.create' => array(
17 'tag_id' => '$value.api.tag.create',
22 $result = civicrm_api3('contact', 'create', $params);
24 catch (CiviCRM_API3_Exception
$e) {
26 $errorMessage = $e->getMessage();
27 $errorCode = $e->getErrorCode();
28 $errorData = $e->getExtraParams();
29 return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData);
36 * Function returns array of result expected from previous function
38 function contact_create_expectedresult(){
40 $expectedResult = array(
48 'contact_type' => 'Individual',
49 'contact_sub_type' => '',
56 'legal_identifier' => '',
57 'external_identifier' => '',
59 'display_name' => 'batman',
63 'preferred_communication_method' => '',
64 'preferred_language' => 'en_US',
65 'preferred_mail_format' => 'Both',
66 'hash' => '67eac7789eaee00',
71 'email_greeting_id' => '1',
72 'email_greeting_custom' => '',
73 'email_greeting_display' => '',
74 'postal_greeting_id' => '1',
75 'postal_greeting_custom' => '',
76 'postal_greeting_display' => '',
77 'addressee_id' => '1',
78 'addressee_custom' => '',
79 'addressee_display' => '',
84 'deceased_date' => '',
85 'household_name' => '',
86 'primary_contact_id' => '',
87 'organization_name' => '',
89 'user_unique_id' => '',
90 'created_date' => '2013-07-28 08:49:19',
91 'modified_date' => '2012-11-14 16:02:35',
92 'api.tag.create' => 6,
93 'api.entity_tag.create' => array(
103 return $expectedResult;
108 * This example has been generated from the API test suite. The test that created it is called
110 * testChainingValuesCreate and can be found in
111 * http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ContactTest.php
113 * You can see the outcome of the API tests at
114 * http://tests.dev.civicrm.org/trunk/results-api_v3
116 * To Learn about the API read
117 * http://book.civicrm.org/developer/current/techniques/api/
119 * and review the wiki at
120 * http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
122 * Read more about testing here
123 * http://wiki.civicrm.org/confluence/display/CRM/Testing
125 * API Standards documentation:
126 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards