Merge pull request #11736 from jitendrapurohit/CRM-21815
[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(
5be22f39 30 'is_error' => 1,
31 'error_message' => $errorMessage,
50fb255d 32 'error_code' => $errorCode,
33 'error_data' => $errorData,
34 );
35 }
36
37 return $result;
6a488035
TO
38}
39
fb32de45 40/**
50fb255d 41 * Function returns array of result expected from previous function.
42 *
43 * @return array
44 * API result array
6a488035 45 */
50fb255d 46function address_create_expectedresult() {
6a488035 47
edb0d67a 48 $expectedResult = array(
50fb255d 49 'is_error' => 0,
50 'version' => 3,
51 'count' => 1,
52 'id' => 2,
53 'values' => array(
edb0d67a 54 '2' => array(
50fb255d 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 ),
6a488035 68 ),
50fb255d 69 );
6a488035 70
fb32de45 71 return $expectedResult;
6a488035
TO
72}
73
a828d7b8 74/*
50fb255d 75* This example has been generated from the API test suite.
a828d7b8
CW
76* The test that created it is called "testCreateAddress"
77* and can be found at:
69d79249 78* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/AddressTest.php
6a488035
TO
79*
80* You can see the outcome of the API tests at
69d79249 81* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
82*
83* To Learn about the API read
69d79249 84* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 85*
69d79249 86* Browse the api on your own site with the api explorer
41d4d31f 87* http://MYSITE.ORG/path/to/civicrm/api
6a488035
TO
88*
89* Read more about testing here
90* http://wiki.civicrm.org/confluence/display/CRM/Testing
91*
92* API Standards documentation:
93* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
b259a4ab 94*/