Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
50fb255d | 2 | /** |
a828d7b8 | 3 | * Test Generated example demonstrating the Contact.create API. |
50fb255d | 4 | * |
5c49fee0 | 5 | * This demonstrates setting a custom field through the API. |
50fb255d | 6 | * |
7 | * @return array | |
8 | * API result array | |
9 | */ | |
10 | function contact_create_example() { | |
11 | $params = array( | |
12 | 'first_name' => 'abc1', | |
13 | 'contact_type' => 'Individual', | |
14 | 'last_name' => 'xyz1', | |
15 | 'custom_1' => 'custom string', | |
16 | ); | |
6a488035 | 17 | |
50fb255d | 18 | try{ |
a828d7b8 | 19 | $result = civicrm_api3('Contact', 'create', $params); |
50fb255d | 20 | } |
21 | catch (CiviCRM_API3_Exception $e) { | |
22 | // Handle error here. | |
23 | $errorMessage = $e->getMessage(); | |
24 | $errorCode = $e->getErrorCode(); | |
25 | $errorData = $e->getExtraParams(); | |
26 | return array( | |
27 | 'error' => $errorMessage, | |
28 | 'error_code' => $errorCode, | |
29 | 'error_data' => $errorData, | |
30 | ); | |
31 | } | |
32 | ||
33 | return $result; | |
6a488035 TO |
34 | } |
35 | ||
fb32de45 | 36 | /** |
50fb255d | 37 | * Function returns array of result expected from previous function. |
38 | * | |
39 | * @return array | |
40 | * API result array | |
6a488035 | 41 | */ |
50fb255d | 42 | function contact_create_expectedresult() { |
6a488035 TO |
43 | |
44 | $expectedResult = array( | |
50fb255d | 45 | 'is_error' => 0, |
46 | 'version' => 3, | |
47 | 'count' => 1, | |
48 | 'id' => 1, | |
49 | 'values' => array( | |
6a488035 | 50 | '1' => array( |
50fb255d | 51 | 'id' => '1', |
52 | 'contact_type' => 'Individual', | |
53 | 'contact_sub_type' => '', | |
54 | 'do_not_email' => 0, | |
55 | 'do_not_phone' => 0, | |
56 | 'do_not_mail' => 0, | |
57 | 'do_not_sms' => 0, | |
58 | 'do_not_trade' => 0, | |
59 | 'is_opt_out' => 0, | |
60 | 'legal_identifier' => '', | |
61 | 'external_identifier' => '', | |
62 | 'sort_name' => 'xyz1, abc1', | |
63 | 'display_name' => 'abc1 xyz1', | |
64 | 'nick_name' => '', | |
65 | 'legal_name' => '', | |
66 | 'image_URL' => '', | |
67 | 'preferred_communication_method' => '', | |
68 | 'preferred_language' => 'en_US', | |
69 | 'preferred_mail_format' => 'Both', | |
70 | 'hash' => '67eac7789eaee00', | |
71 | 'api_key' => '', | |
72 | 'first_name' => 'abc1', | |
73 | 'middle_name' => '', | |
74 | 'last_name' => 'xyz1', | |
75 | 'prefix_id' => '', | |
76 | 'suffix_id' => '', | |
77 | 'formal_title' => '', | |
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' => '', | |
88 | 'job_title' => '', | |
89 | 'gender_id' => '', | |
90 | 'birth_date' => '', | |
91 | 'is_deceased' => 0, | |
92 | 'deceased_date' => '', | |
93 | 'household_name' => '', | |
94 | 'primary_contact_id' => '', | |
95 | 'organization_name' => '', | |
96 | 'sic_code' => '', | |
97 | 'user_unique_id' => '', | |
98 | 'created_date' => '2013-07-28 08:49:19', | |
99 | 'modified_date' => '2012-11-14 16:02:35', | |
100 | ), | |
6a488035 | 101 | ), |
50fb255d | 102 | ); |
6a488035 TO |
103 | |
104 | return $expectedResult; | |
105 | } | |
106 | ||
a828d7b8 | 107 | /* |
50fb255d | 108 | * This example has been generated from the API test suite. |
a828d7b8 CW |
109 | * The test that created it is called "testCreateWithCustom" |
110 | * and can be found at: | |
69d79249 | 111 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php |
1c88e578 | 112 | * |
113 | * You can see the outcome of the API tests at | |
69d79249 | 114 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
fb32de45 | 115 | * |
116 | * To Learn about the API read | |
69d79249 | 117 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
fb32de45 | 118 | * |
69d79249 | 119 | * Browse the api on your own site with the api explorer |
41d4d31f | 120 | * http://MYSITE.ORG/path/to/civicrm/api |
fb32de45 | 121 | * |
6a488035 TO |
122 | * Read more about testing here |
123 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
fb32de45 | 124 | * |
125 | * API Standards documentation: | |
126 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
b259a4ab | 127 | */ |