I'm trying to get Activity information via the API, but have run into two issues:

  1. I cannot seem to filter by a date stored in a custom field. I've tried formatting the date multiple ways ('Y-m-d', 'm-d-Y', 'YmdHis', etc), but it doesn't seem to have any impact.

  2. Since I can't figure out to make the filter work, I thought I would do the filtering myself. But I can't seem to get the custom field to be returned in the results. When I try in the API Explorer, I get all kinds of data back for each activity. But when I copy / paste the PHP code, I only get a small amount of activity fields, and definitely not the custom field I need.

This is the code from the explorer that isn't working for me when I actually use it in code:

$result = civicrm_api3('Activity', 'get', array( 'return' => "custom_46", 'status_id' => "Scheduled", 'activity_type_id' => "TDY", ));

The Explorer shows all activity data for each result. When running the generated PHP code in my code, I only get the Activity ID, Activity Type ID, Status ID, and Source Contact ID.

1 Answer 1


That is weird :-) I assume you have all permission for custom data? And have you tried using the actual ID's for status_id and activity_type_id?

  • Yep, I have all permission for the custom data, and I even tried removing the status and activity type filters. Same results. There seems to be a disconnect between what the API explorer does, and how the API actually works.
    – JuliaK
    Commented Apr 8, 2016 at 15:50
  • Well, I was wrong about the permissions. I'm logged in as User 1, but my code isn't running as me. Thank you so much for pointing me in the right direction!
    – JuliaK
    Commented Apr 8, 2016 at 16:54
  • To clarify, permissions solved for my second issue. Walking through the code, it seems like my custom field filters is being ignored. Also, I'm getting back ALL custom fields, not just the one in my return parameter. But I can get the value and filter myself.
    – JuliaK
    Commented Apr 8, 2016 at 17:09
  • Glad you got there in the end! Commented Apr 11, 2016 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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