Simplify path to api explorer
[civicrm-core.git] / api / v3 / examples / Address / Create.php
1 <?php
2 /**
3 * Test Generated example of using address create API.
4 *
5 *
6 * @return array
7 * API result array
8 */
9 function address_create_example() {
10 $params = array(
11 'contact_id' => 3,
12 'location_type_id' => 6,
13 'street_name' => 'Ambachtstraat',
14 'street_number' => '23',
15 'street_address' => 'Ambachtstraat 23',
16 'postal_code' => '6971 BN',
17 'country_id' => '1152',
18 'city' => 'Brummen',
19 'is_primary' => 1,
20 );
21
22 try{
23 $result = civicrm_api3('address', 'create', $params);
24 }
25 catch (CiviCRM_API3_Exception $e) {
26 // Handle error here.
27 $errorMessage = $e->getMessage();
28 $errorCode = $e->getErrorCode();
29 $errorData = $e->getExtraParams();
30 return array(
31 'error' => $errorMessage,
32 'error_code' => $errorCode,
33 'error_data' => $errorData,
34 );
35 }
36
37 return $result;
38 }
39
40 /**
41 * Function returns array of result expected from previous function.
42 *
43 * @return array
44 * API result array
45 */
46 function address_create_expectedresult() {
47
48 $expectedResult = array(
49 'is_error' => 0,
50 'version' => 3,
51 'count' => 1,
52 'id' => 2,
53 'values' => array(
54 '2' => array(
55 'id' => '2',
56 'contact_id' => '3',
57 'location_type_id' => '6',
58 'is_primary' => '1',
59 'is_billing' => 0,
60 'street_address' => 'Ambachtstraat 23',
61 'street_number' => '23',
62 'street_name' => 'Ambachtstraat',
63 'city' => 'Brummen',
64 'postal_code' => '6971 BN',
65 'country_id' => '1152',
66 'manual_geo_code' => 0,
67 ),
68 ),
69 );
70
71 return $expectedResult;
72 }
73
74 /**
75 * This example has been generated from the API test suite.
76 * The test that created it is called
77 * testCreateAddress
78 * and can be found in
79 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/AddressTest.php
80 *
81 * You can see the outcome of the API tests at
82 * https://test.civicrm.org/job/CiviCRM-master-git/
83 *
84 * To Learn about the API read
85 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
86 *
87 * Browse the api on your own site with the api explorer
88 * http://MYSITE.ORG/path/to/civicrm/api
89 *
90 * Read more about testing here
91 * http://wiki.civicrm.org/confluence/display/CRM/Testing
92 *
93 * API Standards documentation:
94 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
95 */