Merge pull request #13852 from pradpnayak/RecurringMemIssue
[civicrm-core.git] / api / v3 / examples / Contact / Create.php
index 8416af1ebc5f826a84e6b2af8ce43363e18acd6f..a0727ef7e0aac2e9e51f0656576950d9941bdb87 100644 (file)
@@ -1,33 +1,34 @@
 <?php
 /**
- * Test Generated example of using contact create API.
+ * Test Generated example demonstrating the Contact.create API.
  *
- * /*this demonstrates setting a custom field through the API 
+ * This demonstrates setting a custom field through the API.
  *
  * @return array
  *   API result array
  */
 function contact_create_example() {
-  $params = array(
+  $params = [
     'first_name' => 'abc1',
     'contact_type' => 'Individual',
     'last_name' => 'xyz1',
     'custom_1' => 'custom string',
-  );
+  ];
 
   try{
-    $result = civicrm_api3('contact', 'create', $params);
+    $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,
+    return [
+      'is_error' => 1,
+      'error_message' => $errorMessage,
       'error_code' => $errorCode,
       'error_data' => $errorData,
-    );
+    ];
   }
 
   return $result;
@@ -41,14 +42,14 @@ function contact_create_example() {
  */
 function contact_create_expectedresult() {
 
-  $expectedResult = array(
+  $expectedResult = [
     'is_error' => 0,
     'version' => 3,
     'count' => 1,
-    'id' => 1,
-    'values' => array(
-      '1' => array(
-        'id' => '1',
+    'id' => 3,
+    'values' => [
+      '3' => [
+        'id' => '3',
         'contact_type' => 'Individual',
         'contact_sub_type' => '',
         'do_not_email' => 0,
@@ -97,18 +98,17 @@ function contact_create_expectedresult() {
         'user_unique_id' => '',
         'created_date' => '2013-07-28 08:49:19',
         'modified_date' => '2012-11-14 16:02:35',
-      ),
-    ),
-  );
+      ],
+    ],
+  ];
 
   return $expectedResult;
 }
 
-/**
+/*
 * This example has been generated from the API test suite.
-* The test that created it is called
-* testCreateWithCustom
-* and can be found in
+* The test that created it is called "testCreateWithCustom"
+* and can be found at:
 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
 *
 * You can see the outcome of the API tests at