3 * Test Generated example demonstrating the Contact.create API.
5 * This demonstrates setting a custom field through the API.
10 function contact_create_example() {
12 'first_name' => 'abc1',
13 'contact_type' => 'Individual',
14 'last_name' => 'xyz1',
15 'custom_1' => 'custom string',
19 $result = civicrm_api3('Contact', 'create', $params);
21 catch (CiviCRM_API3_Exception
$e) {
23 $errorMessage = $e->getMessage();
24 $errorCode = $e->getErrorCode();
25 $errorData = $e->getExtraParams();
27 'error' => $errorMessage,
28 'error_code' => $errorCode,
29 'error_data' => $errorData,
37 * Function returns array of result expected from previous function.
42 function contact_create_expectedresult() {
44 $expectedResult = array(
52 'contact_type' => 'Individual',
53 'contact_sub_type' => '',
60 'legal_identifier' => '',
61 'external_identifier' => '',
62 'sort_name' => 'xyz1, abc1',
63 'display_name' => 'abc1 xyz1',
67 'preferred_communication_method' => '',
68 'preferred_language' => 'en_US',
69 'preferred_mail_format' => 'Both',
70 'hash' => '67eac7789eaee00',
72 'first_name' => 'abc1',
74 'last_name' => 'xyz1',
78 'communication_style_id' => '',
79 'email_greeting_id' => '1',
80 'email_greeting_custom' => '',
81 'email_greeting_display' => '',
82 'postal_greeting_id' => '1',
83 'postal_greeting_custom' => '',
84 'postal_greeting_display' => '',
85 'addressee_id' => '1',
86 'addressee_custom' => '',
87 'addressee_display' => '',
92 'deceased_date' => '',
93 'household_name' => '',
94 'primary_contact_id' => '',
95 'organization_name' => '',
97 'user_unique_id' => '',
98 'created_date' => '2013-07-28 08:49:19',
99 'modified_date' => '2012-11-14 16:02:35',
104 return $expectedResult;
108 * This example has been generated from the API test suite.
109 * The test that created it is called "testCreateWithCustom"
110 * and can be found at:
111 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
113 * You can see the outcome of the API tests at
114 * https://test.civicrm.org/job/CiviCRM-master-git/
116 * To Learn about the API read
117 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
119 * Browse the api on your own site with the api explorer
120 * http://MYSITE.ORG/path/to/civicrm/api
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