Im using API3 to get activities

My code is

function hook_any_activity_get($cid,$type) {
  $params = [
    'contact_id' => $cid,
    'activity_type_id' => $type,
    'sequential' => 1,
    'is_deleted' => 0,
    $result = civicrm_api3('Activity', 'get', $params);
  catch (CiviCRM_API3_Exception $e) {
    // Handle error here.
    $errorMessage = $e->getMessage();
    $errorCode = $e->getErrorCode();
    $errorData = $e->getExtraParams();
    return [
      'is_error' => 1,
      'error_message' => $errorMessage,
      'error_code' => $errorCode,
      'error_data' => $errorData,
  return $result;

This works fine when the activity is created outside of a case.

When the activity is created within a case I get an error

One of parameters (value: ) is not of the type Positive

I have tried this written into a module and in Drupal rules. Same error.

I'm not seeing anything in backtrace or the CiviCRM log file.

Ive even tried it just by trying to return the activity using the activity ID.

I also tried it by including the case ID


Turns out there is a bug in the CiviMobile extension that is breaking this functionality. Disabling this extension fixes the problem.


There is an extension for a case activity API, although I have not tested it for a while! https://civicrm.org/extensions/caseactivity-api That might help you?


Parameter contact_id should be target_contact_id (if looking for client) or source_contact_id (if looking for author).

  • There is a catchall for any activity contact in the API called contact_id...but I tried your suggestion as well - same error. Feb 5 '20 at 15:12
  • Oh ok. Is there a stack trace in ConfigAndLog? I don't get an error.
    – Demerit
    Feb 5 '20 at 15:14
  • I wish. Nothing. Are you using PHP to test or are you using the API explorer? Feb 5 '20 at 16:07
  • I used cv php:eval. Actually if you're catching the exception yourself then there won't be a stacktrace in the log. You can either put debug_backtrace() in your error handler, or let civi log the error instead (don't catch the error).
    – Demerit
    Feb 5 '20 at 16:17
  • OK on this I used a Drupal view to get the ID of the activity I wanted. I put this into a Drupal rule to load the activity entity by activity ID - and it will not load it there either. Im just wondering if when it is part of a case, there is a permissions issue with it? Feb 6 '20 at 10:06

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.