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