Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-16959

Correctly support multiple contacts/groups in GroupContact Create API

    Details

    • Type: Improvement
    • Status: Done/Fixed
    • Priority: Minor
    • Resolution: Fixed/Completed
    • Affects Version/s: 4.6.5, 4.7
    • Fix Version/s: 4.7
    • Component/s: None
    • Labels:
      None
    • Documentation Required?:
      None
    • Funding Source:
      Contributed Code

      Description

      When using the API GroupContact Create

      You will hit an error if you try to add multiple contacts to multiple groups, eg:

      $result = civicrm_api3('GroupContact', 'create', array(
      'sequential' => 1,
      'contact_id' => array(140, 32),
      'group_id' => 1,
      ));

      This is because the API expects multiple contacts to be added as contact_id.1, contact_id.2 according to the comments. If you try to use the array (as created by the API explorer) then code adds the array to an array, which breaks the underlaying BAO.

      I would like to standardise this part of the GroupContact API, but I would like some guidance:

      1 - What is the 'correct' approach here if you want to add multiple contacts to a group? Put the contact IDs in an array, as per the API explorer? Or is it not sensible to try to cater for multiple contacts/groups at all?

      2 - If it makes sense to go ahead with this, do we need to preserve the 'legacy' behavior of the API looking for contact_id.1, .2, etc ?

      3 - I noticed there are several places in the current code that checks for mandatory fields. What is the correct approach for checking for mandatory fields, I would assume it is via the ACTION_spec()? Can any other checks for mandatory fields be removed in favour of this? I've noticed that civicrm_api3_verify_mandatory() is used in some places as well for example.

        Attachments

          Activity

            People

            • Assignee:
              colemanw Coleman Watts
              Reporter:
              john John K.
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour
                1h