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.