4

I think this is a bug.

From the API Explorer, I can successfully run this to create a new case, and it is auto-populated with the default Sequence:

$result = civicrm_api3('Case', 'create', array(
  'sequential' => 1,   
  'contact_id' => 4243,
  'case_type_id' => "member_application",
  'creator_id' => 1033,
  'subject' => "Application",
  'medium_id' => 6,
));

But running that same code as a hook fails with the error:

CiviCRM_API3_Exception: "source_contact_id is not a valid integer"

It actually does create the case and the initial Open Case activity, but seems to fail while trying to create the first activity in my Sequence, which is not created.

I can fix it by editing api/v3/utils.php and adding this at line 1956:

if ($fieldValue =='user_contact_id')
  $fieldValue = 1033;

I think what's happening is that somewhere along the line, it sets the value of source_contact_id to 'user_contact_id'. The _civicrm_api3_validate_integer function is supposed to replace this with the currently logged in user. This works correctly when running from the API Explorer, but not when running from a hook.

The proper solution would be to pass the API "creator_id" through to "source_contact_id" for the extra activities, but I don't know how to fix that. My hack to hard code the contact works for me for now.

2

Thanks for sharing this, I agree that it looks like a bug. Instructions on filing a bug report here: https://civicrm.org/bug-reporting

0

I believe this is normal behavior for the api, although the error message is a bit obtuse. By default it will not create cases or activities (or anything else for that matter) if the logged-in user does not have permission to do so.

Add 'check_permissions' => 0 to your api params if you wish it to proceed without permission checks.

  • I tried adding 'check_permissions' => 0 to no effect. (Isn't it 0 by default anyway? Or is that for certain other sets of the API?) – Norris Jun 12 '15 at 19:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.