updated examples
[civicrm-core.git] / api / v3 / examples / Contact / Create.php
1 <?php
2 /**
3 * Test Generated example of using contact create API
4 * /*this demonstrates setting a custom field through the API *
5 */
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 );
13
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 }
24
25 return $result;
26 }
27
28 /**
29 * Function returns array of result expected from previous function
30 */
31 function contact_create_expectedresult(){
32
33 $expectedResult = array(
34 'is_error' => 0,
35 'version' => 3,
36 'count' => 1,
37 'id' => 1,
38 'values' => array(
39 '1' => array(
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',
64 'prefix_id' => '',
65 'suffix_id' => '',
66 'formal_title' => '',
67 'communication_style_id' => '',
68 'email_greeting_id' => '1',
69 'email_greeting_custom' => '',
70 'email_greeting_display' => '',
71 'postal_greeting_id' => '1',
72 'postal_greeting_custom' => '',
73 'postal_greeting_display' => '',
74 'addressee_id' => '1',
75 'addressee_custom' => '',
76 'addressee_display' => '',
77 'job_title' => '',
78 'gender_id' => '',
79 'birth_date' => '',
80 'is_deceased' => 0,
81 'deceased_date' => '',
82 'household_name' => '',
83 'primary_contact_id' => '',
84 'organization_name' => '',
85 'sic_code' => '',
86 'user_unique_id' => '',
87 'created_date' => '2013-07-28 08:49:19',
88 'modified_date' => '2012-11-14 16:02:35',
89 ),
90 ),
91 );
92
93 return $expectedResult;
94 }
95
96
97 /*
98 * This example has been generated from the API test suite. The test that created it is called
99 *
100 * testCreateWithCustom and can be found in
101 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
102 *
103 * You can see the outcome of the API tests at
104 * https://test.civicrm.org/job/CiviCRM-master-git/
105 *
106 * To Learn about the API read
107 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
108 *
109 * Browse the api on your own site with the api explorer
110 * http://MYSITE.ORG/path/to/civicrm/api/explorer
111 *
112 * Read more about testing here
113 * http://wiki.civicrm.org/confluence/display/CRM/Testing
114 *
115 * API Standards documentation:
116 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
117 */