3 * Test Generated example of using contact create API
4 * /*this demonstrates setting a custom field through the API *
6 function contact_create_example(){
8 'first_name' => 'abc1',
9 'contact_type' => 'Individual',
10 'last_name' => 'xyz1',
11 'custom_1' => 'custom string',
15 $result = civicrm_api3('contact', 'create', $params);
17 catch (CiviCRM_API3_Exception
$e) {
19 $errorMessage = $e->getMessage();
20 $errorCode = $e->getErrorCode();
21 $errorData = $e->getExtraParams();
22 return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData);
29 * Function returns array of result expected from previous function
31 function contact_create_expectedresult(){
33 $expectedResult = array(
41 'contact_type' => 'Individual',
42 'contact_sub_type' => '',
49 'legal_identifier' => '',
50 'external_identifier' => '',
51 'sort_name' => 'xyz1, abc1',
52 'display_name' => 'abc1 xyz1',
56 'preferred_communication_method' => '',
57 'preferred_language' => 'en_US',
58 'preferred_mail_format' => 'Both',
59 'hash' => '67eac7789eaee00',
61 'first_name' => 'abc1',
63 'last_name' => 'xyz1',
67 'communication_style_id' => '',
68 'email_greeting_id' => '1',
69 'email_greeting_custom' => '',
70 'email_greeting_display' => '',
71 'postal_greeting_id' => '1',
72 'postal_greeting_custom' => '',
73 'postal_greeting_display' => '',
74 'addressee_id' => '1',
75 'addressee_custom' => '',
76 'addressee_display' => '',
81 'deceased_date' => '',
82 'household_name' => '',
83 'primary_contact_id' => '',
84 'organization_name' => '',
86 'user_unique_id' => '',
87 'created_date' => '2013-07-28 08:49:19',
88 'modified_date' => '2012-11-14 16:02:35',
93 return $expectedResult;
98 * This example has been generated from the API test suite. The test that created it is called
100 * testCreateWithCustom and can be found in
101 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
103 * You can see the outcome of the API tests at
104 * https://test.civicrm.org/job/CiviCRM-master-git/
106 * To Learn about the API read
107 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
109 * Browse the api on your own site with the api explorer
110 * http://MYSITE.ORG/path/to/civicrm/api/explorer
112 * Read more about testing here
113 * http://wiki.civicrm.org/confluence/display/CRM/Testing
115 * API Standards documentation:
116 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards