Merge pull request #5086 from deepak-srivastava/CRM-15490
[civicrm-core.git] / api / v3 / examples / Contact / FormatOnlyID.php
1 <?php
2 /**
3 * @file
4 * Test Generated API Example.
5 * See bottom of this file for more detail.
6 */
7
8 /**
9 * Test Generated example of using contact get API.
10 *
11 * This demonstrates use of the 'format.id_only' param.
12 /* This param causes the id of the only entity to be returned as an integer.
13 /* it will be ignored if there is not exactly 1 result
14 *
15 * @return array
16 * API result array
17 */
18 function contact_get_example() {
19 $params = array(
20 'id' => 17,
21 'format.only_id' => 1,
22 );
23
24 try{
25 $result = civicrm_api3('contact', 'get', $params);
26 }
27 catch (CiviCRM_API3_Exception $e) {
28 // Handle error here.
29 $errorMessage = $e->getMessage();
30 $errorCode = $e->getErrorCode();
31 $errorData = $e->getExtraParams();
32 return array(
33 'error' => $errorMessage,
34 'error_code' => $errorCode,
35 'error_data' => $errorData,
36 );
37 }
38
39 return $result;
40 }
41
42 /**
43 * Function returns array of result expected from previous function.
44 *
45 * @return array
46 * API result array
47 */
48 function contact_get_expectedresult() {
49
50 $expectedResult = 17;
51
52 return $expectedResult;
53 }
54
55 /**
56 * This example has been generated from the API test suite.
57 * The test that created it is called
58 * testContactGetFormatID_only
59 * and can be found in
60 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
61 *
62 * You can see the outcome of the API tests at
63 * https://test.civicrm.org/job/CiviCRM-master-git/
64 *
65 * To Learn about the API read
66 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
67 *
68 * Browse the api on your own site with the api explorer
69 * http://MYSITE.ORG/path/to/civicrm/api/explorer
70 *
71 * Read more about testing here
72 * http://wiki.civicrm.org/confluence/display/CRM/Testing
73 *
74 * API Standards documentation:
75 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
76 */