Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
50fb255d | 2 | /** |
3 | * Test Generated example of using contact create API. | |
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{ |
19 | $result = civicrm_api3('contact', 'create', $params); | |
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 | ||
50fb255d | 107 | /** |
108 | * This example has been generated from the API test suite. | |
109 | * The test that created it is called | |
110 | * testCreateWithCustom | |
111 | * and can be found in | |
69d79249 | 112 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php |
1c88e578 | 113 | * |
114 | * You can see the outcome of the API tests at | |
69d79249 | 115 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
fb32de45 | 116 | * |
117 | * To Learn about the API read | |
69d79249 | 118 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
fb32de45 | 119 | * |
69d79249 | 120 | * Browse the api on your own site with the api explorer |
41d4d31f | 121 | * http://MYSITE.ORG/path/to/civicrm/api |
fb32de45 | 122 | * |
6a488035 TO |
123 | * Read more about testing here |
124 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
fb32de45 | 125 | * |
126 | * API Standards documentation: | |
127 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
b259a4ab | 128 | */ |