- if ($todo['params']['version'] == 4) {
- $todo['params']['checkPermissions'] = FALSE;
- }
-
- $result = civicrm_api($todo['entity_type'], 'create', ['debug' => TRUE] + $todo['params']);
- if (!empty($result['is_error'])) {
- $this->onApiError($todo['entity_type'], 'create', $todo['params'], $result);
+ $params = $todo['params'];
+ // APIv4
+ if ($params['version'] == 4) {
+ $params['checkPermissions'] = FALSE;
+ // Use "save" instead of "create" action to accommodate a "match" param
+ $params['records'] = [$params['values']];
+ unset($params['values']);
+ $result = civicrm_api4($todo['entity_type'], 'save', $params);
+ $id = $result->first()['id'];
+ }
+ // APIv3
+ else {
+ $result = civicrm_api($todo['entity_type'], 'create', $params);
+ if (!empty($result['is_error'])) {
+ $this->onApiError($todo['entity_type'], 'create', $params, $result);
+ }
+ $id = $result['id'];