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