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