CRM-7645 API v3 contact update API should not check for required fields

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Major
    • Resolution: Fixed/Completed
    • Affects Version/s: 3.4.0, 4.0.0
    • Fix Version/s: 3.4.alpha
    • Component/s: CiviCRM API
    • Labels:
      None

      Description

      API v3 is looking checking for required fields for contacts. For example when updating individuals it checks for 'first_name' and 'last_name' or 'email'. This of course doesn't make sense during an update since the update can act solely on other fields. Of course on the other hand if we don't do any verification someone could use the api to unset a required field, but that to check for that might be excessive.

        Attachments

          Activity

          [CRM-7645] API v3 contact update API should not check for required fields
          Eileen McNaughton added a comment -

          Just a note on this

          _civicrm_api3_contact_update

          should be removed.

          The correct call should be

          civicrm_api('Contact','Update',$params);

          We need a test to make sure this works

          Eileen McNaughton added a comment -

          How did this get to be marked priority major???

          Anyway, I confirm that this works better in api v3 - check out the example from the test

          public function testUpdateCreateWithID()

          { // Insert a row in civicrm_contact creating individual contact $op = new PHPUnit_Extensions_Database_Operation_Insert( ); $op->execute( $this->_dbconn, new PHPUnit_Extensions_Database_DataSet_XMLDataSet( dirname(__FILE__) . '/dataset/contact_ind.xml') ); $params = array( 'id' => 23, 'first_name' => 'abcd', 'last_name' => 'wxyz', 'version' => $this->_apiversion, ); $result = civicrm_api('Contact','Update',$params); $this->assertTrue( is_array( $result ) ); $this->assertEquals( 0, $result['is_error'] ); }
          dave hansen-lange added a comment -

          This was on API v3 CiviCRM 4.0Alpha1. It's major because if you try to update a contact without passing in the required fields you get an error and the update fails.

          Unless I'm missing something the test that you wrote does not show that this isn't happening. Required fields are
          (email OR first name AND last name) AND (whatever custom fields are marked as mandatory)

          Erik Hommel added a comment -

          I have done the following test with the latest API v3:

          /civicrm/ajax/rest&json=1&debug=1&version=3&entity=Contact&action=update&id=1&gender_id=3

          and get the following result:
          {
          "is_error":0,
          "undefined_fields":["contact_id",
          "gender",
          "address_id",
          "street_address",
          "city",
          "postal_code",
          "state_province_id",
          "state_province_name",
          "state_province",
          "country_id",
          "country",
          "phone_id",
          "phone_type_id",
          "phone",
          "email_id",
          "email",
          "on_hold",
          "worldregion_id",
          "world_region",
          "IDS_request_uri",
          "IDS_user_agent",
          "check_permissions",
          "custom"],
          "version":3,
          "count":1,
          "id":1,
          "values":{
          "1":

          { "id":"1", "contact_type":"Individual", "contact_sub_type":null, "do_not_email":"0", "do_not_phone":"0", "do_not_mail":"0", "do_not_sms":"0", "do_not_trade":"0", "is_opt_out":"0", "legal_identifier":null, "external_identifier":null, "sort_name":"Hommel, Erik", "display_name":"Erik Hommel", "nick_name":null, "legal_name":null, "image_URL":"http:\/\/localhost\/core\/sites\/default\/files\/civicrm\/custom\/SDC10808_63e883d57c555f3c7dab75109dece7f3.JPG", "preferred_communication_method":null, "preferred_language":null, "preferred_mail_format":"Both", "hash":null, "api_key":null, "first_name":"Erik", "middle_name":null, "last_name":"Hommel", "prefix_id":null, "suffix_id":null, "email_greeting_id":null, "email_greeting_custom":null, "email_greeting_display":null, "postal_greeting_id":null, "postal_greeting_custom":null, "postal_greeting_display":null, "addressee_id":null, "addressee_custom":null, "addressee_display":null, "job_title":"partner", "gender_id":"3", "birth_date":"19630401000000", "is_deceased":"0", "deceased_date":null, "household_name":null, "primary_contact_id":null, "organization_name":null, "sic_code":null, "user_unique_id":null }

          }
          }

          In a PHP call:
          $params = array(
          'id' => '1',
          'gender_id' => '3',
          'version' => '3');

          $result = civicrm_api( 'Contact', 'Update', $params);

          with result:
          Array ( [is_error] => 0 [version] => 3 [count] => 1 [id] => 1 [values] => Array ( [1] => Array ( [id] => 1 [contact_type] => Individual [contact_sub_type] => [do_not_email] => 0 [do_not_phone] => 0 [do_not_mail] => 0 [do_not_sms] => 0 [do_not_trade] => 0 [is_opt_out] => 0 [legal_identifier] => [external_identifier] => [sort_name] => Hommel, Erik [display_name] => Erik Hommel [nick_name] => [legal_name] => [image_URL] => http://localhost/core/sites/default/files/civicrm/custom/SDC10808_63e883d57c555f3c7dab75109dece7f3.JPG [preferred_communication_method] => [preferred_language] => [preferred_mail_format] => Both [hash] => [api_key] => [first_name] => Erik [middle_name] => [last_name] => Hommel [prefix_id] => [suffix_id] => [email_greeting_id] => [email_greeting_custom] => [email_greeting_display] => [postal_greeting_id] => [postal_greeting_custom] => [postal_greeting_display] => [addressee_id] => [addressee_custom] => [addressee_display] => [job_title] => partner [gender_id] => 3 [birth_date] => 19630401000000 [is_deceased] => 0 [deceased_date] => [household_name] => [primary_contact_id] => [organization_name] => [sic_code] => [user_unique_id] => ) ) )

          This does prove that I can update a contact without passing first name or last name. I will remove the civicrm_api3_contact_update function and close the issue.

          Erik Hommel added a comment -

          Let me rephrase that: I will not remove the function yet, but close the issue.

          Erik Hommel added a comment -

          Solved in later version of v3 Contact API

          dave hansen-lange added a comment -

          awesome.

            People

            • Assignee:
              Erik Hommel
              Reporter:
              dave hansen-lange

              Dates

              • Created:
                Updated:
                Resolved: