CRM-15988 - Update generated examples
[civicrm-core.git] / api / v3 / examples / Contact / Create.php
1 <?php
2 /**
3 * Test Generated example demonstrating the Contact.create API.
4 *
5 * This demonstrates setting a custom field through the API.
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 );
17
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;
34 }
35
36 /**
37 * Function returns array of result expected from previous function.
38 *
39 * @return array
40 * API result array
41 */
42 function contact_create_expectedresult() {
43
44 $expectedResult = array(
45 'is_error' => 0,
46 'version' => 3,
47 'count' => 1,
48 'id' => 1,
49 'values' => array(
50 '1' => array(
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 ),
101 ),
102 );
103
104 return $expectedResult;
105 }
106
107 /*
108 * This example has been generated from the API test suite.
109 * The test that created it is called "testCreateWithCustom"
110 * and can be found at:
111 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
112 *
113 * You can see the outcome of the API tests at
114 * https://test.civicrm.org/job/CiviCRM-master-git/
115 *
116 * To Learn about the API read
117 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
118 *
119 * Browse the api on your own site with the api explorer
120 * http://MYSITE.ORG/path/to/civicrm/api
121 *
122 * Read more about testing here
123 * http://wiki.civicrm.org/confluence/display/CRM/Testing
124 *
125 * API Standards documentation:
126 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
127 */