Answers.Body: <p>Let's say <code>$params</code> is enough to find the <strong>single</strong> activity, e.g. <code>$params = ['activity_id' =&gt; 123]</code> where 123 is the known Id. But it could be any other API acceptable params.</p>
  
  <pre><code>$result = civicrm_api3('activity', 'getsingle', $params)
          + civicrm_api3('activity', 'getsingle',
                         [return:'custom_%,activity_type_id'] + $params);
  </code></pre>
  
  <p>The <code>custom_%</code> results in all custom fields being added. But this won't work without <code>activity_type_id</code> also being requested.</p>
  
  <p>(You probably know, but the <code>$array1 + $array2</code> stuff in PHP means extend array 1 with key/value pairs from array 2 when the key from array 2 does not exist in array 1.)</p>
  
  <h2>Alternative method</h2>
  
  <p>You can, list every field in the activity table as well as the custom stuff and in the <code>return</code> parameter to one API call.</p>
  
  <p>However, this assumes that you know all the fields and that they won't change over time/upgrades. So the 2-call method above ensures that you're getting all CiviCRM has to offer on your activities. (Although you have to do extra calls to get the related contacts like targets and assignees etc. of course). It could be argued that you should only request what you want anyway.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-04T12:27:26.097Z
Answers.LastActivityDate: 2015-09-04T12:27:26.097Z
Answers.UserDisplayName: artfulrobot
Body: <p>I hope this is a useful question + answer. I feel it's necessary to document some, um, quirks, of the API v3 around Activities and custom data, because as a developer this took me ages to figure out.</p>
  
  <p><strong>I want to fetch all the details of a single activity, including custom fields.</strong> </p>
  
  <p>Currently (4.6.7):</p>
  
  <ul>
  <li>The normal activity get methods omit the custom fields.</li>
  <li>You can get the custom fields using some voodo, but then you don't get all the standard fields.</li>
  </ul>
  
Tags: <api><activities><4.6>
Title: How to fetch activity including custom fields using API
ThreadText: # How to fetch activity including custom fields using API
  
  (Asked by: username_0 on 2015-09-04)
  
  I hope this is a useful question + answer. I feel it's necessary to document some, um, quirks, of the API v3 around Activities and custom data, because as a developer this took me ages to figure out.
  
  **I want to fetch all the details of a single activity, including custom fields.**
  
  Currently (4.6.7):
  
  * The normal activity get methods omit the custom fields.
  * You can get the custom fields using some voodo, but then you don't get all the standard fields.
  
  **Tags:** api, activities, 4.6
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2015-09-04. Score: 2 | Accepted answer
  
  Let's say `$params` is enough to find the **single** activity, e.g. `$params = ['activity_id' => 123]` where 123 is the known Id. But it could be any other API acceptable params.
  
  ```
  $result = civicrm_api3('activity', 'getsingle', $params)
          + civicrm_api3('activity', 'getsingle',
                         [return:'custom_%,activity_type_id'] + $params);
  
  ```
  
  The `custom_%` results in all custom fields being added. But this won't work without `activity_type_id` also being requested.
  
  (You probably know, but the `$array1 + $array2` stuff in PHP means extend array 1 with key/value pairs from array 2 when the key from array 2 does not exist in array 1.)
  
  ## Alternative method
  
  You can, list every field in the activity table as well as the custom stuff and in the `return` parameter to one API call.
  
  However, this assumes that you know all the fields and that they won't change over time/upgrades. So the 2-call method above ensures that you're getting all CiviCRM has to offer on your activities. (Although you have to do extra calls to get the related contacts like targets and assignees etc. of course). It could be argued that you should only request what you want anyway.
  
  
  ---
  
  