updated examples
[civicrm-core.git] / api / v3 / examples / Contact / FormatIsSuccess_Fail.php
index 481580e94fbc3ba3d2460e7f8df1222e1f641751..60dad237bea97bf53ba5eb3d4ee472b8b0932aa5 100644 (file)
@@ -1,29 +1,37 @@
 <?php
-
-/*
- This demonstrates use of the 'format.is_success' param.
-    This param causes only the success or otherwise of the function to be returned as BOOLEAN
+/**
+ * Test Generated example of using contact create API
This demonstrates use of the 'format.is_success' param.
+    This param causes only the success or otherwise of the function to be returned as BOOLEAN *
  */
 function contact_create_example(){
 $params = array(
-  'version' => 3,
   'id' => 500,
   'format.is_success' => 1,
 );
 
-  $result = civicrm_api( 'contact','create',$params );
+try{
+  $result = civicrm_api3('contact', 'create', $params);
+}
+catch (CiviCRM_API3_Exception $e) {
+  // handle error here
+  $errorMessage = $e->getMessage();
+  $errorCode = $e->getErrorCode();
+  $errorData = $e->getExtraParams();
+  return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData);
+}
 
-  return $result;
+return $result;
 }
 
-/*
+/**
  * Function returns array of result expected from previous function
  */
 function contact_create_expectedresult(){
 
   $expectedResult = 0;
 
-  return $expectedResult  ;
+  return $expectedResult;
 }
 
 
@@ -47,4 +55,4 @@ function contact_create_expectedresult(){
 *
 * API Standards documentation:
 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
-*/
\ No newline at end of file
+*/