test tweaks and updated examples
[civicrm-core.git] / api / v3 / examples / ContactCreate.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 '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' => '',
85 'created_date' => '2013-07-28 08:49:19',
86 'modified_date' => '2012-11-14 16:02:35',
87 ),
88 ),
89 );
90
91 return $expectedResult;
92 }
93
94
95 /*
96 * This example has been generated from the API test suite. The test that created it is called
97 *
98 * testCreateWithCustom and can be found in
99 * http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ContactTest.php
100 *
101 * You can see the outcome of the API tests at
102 * http://tests.dev.civicrm.org/trunk/results-api_v3
103 *
104 * To Learn about the API read
105 * http://book.civicrm.org/developer/current/techniques/api/
106 *
107 * and review the wiki at
108 * http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
109 *
110 * Read more about testing here
111 * http://wiki.civicrm.org/confluence/display/CRM/Testing
112 *
113 * API Standards documentation:
114 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
115 */