Merge pull request #10016 from ErichBSchulz/refaction_entity_action_permissions
[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 'is_error' => 1,
28 'error_message' => $errorMessage,
29 'error_code' => $errorCode,
30 'error_data' => $errorData,
31 );
32 }
33
34 return $result;
35 }
36
37 /**
38 * Function returns array of result expected from previous function.
39 *
40 * @return array
41 * API result array
42 */
43 function contact_create_expectedresult() {
44
45 $expectedResult = array(
46 'is_error' => 0,
47 'version' => 3,
48 'count' => 1,
49 'id' => 3,
50 'values' => array(
51 '3' => array(
52 'id' => '3',
53 'contact_type' => 'Individual',
54 'contact_sub_type' => '',
55 'do_not_email' => 0,
56 'do_not_phone' => 0,
57 'do_not_mail' => 0,
58 'do_not_sms' => 0,
59 'do_not_trade' => 0,
60 'is_opt_out' => 0,
61 'legal_identifier' => '',
62 'external_identifier' => '',
63 'sort_name' => 'xyz1, abc1',
64 'display_name' => 'abc1 xyz1',
65 'nick_name' => '',
66 'legal_name' => '',
67 'image_URL' => '',
68 'preferred_communication_method' => '',
69 'preferred_language' => 'en_US',
70 'preferred_mail_format' => 'Both',
71 'hash' => '67eac7789eaee00',
72 'api_key' => '',
73 'first_name' => 'abc1',
74 'middle_name' => '',
75 'last_name' => 'xyz1',
76 'prefix_id' => '',
77 'suffix_id' => '',
78 'formal_title' => '',
79 'communication_style_id' => '',
80 'email_greeting_id' => '1',
81 'email_greeting_custom' => '',
82 'email_greeting_display' => '',
83 'postal_greeting_id' => '1',
84 'postal_greeting_custom' => '',
85 'postal_greeting_display' => '',
86 'addressee_id' => '1',
87 'addressee_custom' => '',
88 'addressee_display' => '',
89 'job_title' => '',
90 'gender_id' => '',
91 'birth_date' => '',
92 'is_deceased' => 0,
93 'deceased_date' => '',
94 'household_name' => '',
95 'primary_contact_id' => '',
96 'organization_name' => '',
97 'sic_code' => '',
98 'user_unique_id' => '',
99 'created_date' => '2013-07-28 08:49:19',
100 'modified_date' => '2012-11-14 16:02:35',
101 ),
102 ),
103 );
104
105 return $expectedResult;
106 }
107
108 /*
109 * This example has been generated from the API test suite.
110 * The test that created it is called "testCreateWithCustom"
111 * and can be found at:
112 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
113 *
114 * You can see the outcome of the API tests at
115 * https://test.civicrm.org/job/CiviCRM-master-git/
116 *
117 * To Learn about the API read
118 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
119 *
120 * Browse the api on your own site with the api explorer
121 * http://MYSITE.ORG/path/to/civicrm/api
122 *
123 * Read more about testing here
124 * http://wiki.civicrm.org/confluence/display/CRM/Testing
125 *
126 * API Standards documentation:
127 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
128 */