Answers.Body: <p>you could try using the latest version of the <a href="http://dmaster.demo.civicrm.org/civicrm/api#explorer" rel="nofollow">API explorer</a> to give you an idea of the API call. In general, if the custom field is attached to that entity you can just get it using the custom field number. The custom field number is the ID of the field, eg:</p>
  
  <pre><code>$result = civicrm_api3('Case', 'get', array(
  'sequential' =&gt; 1,
  'return' =&gt; "custom_315",
  'id' =&gt; 1,
  ));
  </code></pre>
  
  <p>or REST:</p>
  
  <pre><code>/sites/all/modules/civicrm/extern/rest.php?entity=Case&amp;action=get&amp;api_key=yourkey&amp;key=sitekey&amp;json={"sequential":1,"return":"custom_13","id":1}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-10T10:18:34.470Z
Answers.Text: One way with no results:
  
  /civicrm/ajax/rest?entity=CustomValue&action=get&debug=1&sequential=1&json=1&entity_id=533&return.civicrm_value_attachments_52:file_upload_1_316=1&entity_id=533
  
  {
   "is_error":0,
   "undefined_fields":["return_civicrm_value_attachments_52:file_upload_1_316"],
   "version":3,
   "count":0,
   "values":[],
   "xdebug":{
    "peakMemory":41865784,
    "memory":41708336,
    "timeIndex":0.706025123596
   }
  }
  
  Tried this, but data not present in response:
  /civicrm/ajax/rest?entity=Case&action=get&debug=1&sequential=1&json=1&id=533&return=file_upload_1_316
  
  No luck.
Answers.UserDisplayName: Adam
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-10T10:20:37.323Z
Answers.Text: Also tried (with and without custom_)
  
  `code`
  /civicrm/ajax/rest?entity=Case&action=get&debug=1&sequential=1&json=1&id=533&return=custom_file_upload_1_316
  `code`
  
  with no luck and 
  
  `code`
  /civicrm/ajax/rest?entity=Case&action=get&debug=1&sequential=1&json=1&id=533&return.custom_file_upload_1_316=1
  `code`
Answers.UserDisplayName: Adam
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-10T10:34:05.977Z
Answers.Text: Thanks @john. Still no results using your method with: /civicrm/ajax/rest?entity=Case&action=get&debug=1&sequential=1&json=1&id=533&return.custom_315=1 or /civicrm/ajax/rest?entity=Case&action=get&debug=1&sequential=1&json=1&id=533&return=custom_315
Answers.UserDisplayName: Adam
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-10T10:38:48.543Z
Answers.Text: Using the API docs explorer, it seems the field names are accurate: custom_316 File Upload 1 Case::Attachments File
  custom_317 File Upload 2 Case::Attachments File
  custom_318 File Upload 3 Case::Attachments File
  custom_319 File Upload 4 Case::Attachments File
Answers.UserDisplayName: Adam
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-10T10:43:52.160Z
Answers.Text: The following seems to return the file ID as 'latest'
  
  /civicrm/ajax/rest?entity=CustomValue&action=get&debug=1&sequential=1&json=1&return.custom_316=1&entity_id=533
  
  {
   "is_error":0,
   "undefined_fields":["return_custom_316"],
   "version":3,
   "count":1,
   "id":316,
   "values":[{
    "entity_id":"533",
    "latest":"39",
    "id":"316",
    "0":"39"
   }],
   "xdebug":{
    "peakMemory":41831656,
    "memory":41690848,
    "timeIndex":0.714242935181
   }
  }
  
  I guess I'll have to use the ID to perform another query on the file itself using the ID. I would chain, but the explorer in this CiviCRM isn't up to the latest.
Answers.UserDisplayName: Adam
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-10T11:03:20.000Z
Answers.Text: I've added the syntax for the REST call to the answer, see if that works for you?
Answers.UserDisplayName: John
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-10T10:08:38.570Z
Answers.LastActivityDate: 2015-08-10T11:03:52.380Z
Answers.LastEditDate: 2015-08-10T11:03:52.380Z
Answers.UserDisplayName: John
Body: <p>I'm trying to query the API on CiviCRM 4.4.6 for a Custom Field (Attachment) on a Case and an Activity.</p>
  
  <p>I've tried the examples here: <a href="http://wiki.civicrm.org/confluence/display/CRMDOC/Using+Custom+Data+with+the+API" rel="nofollow">http://wiki.civicrm.org/confluence/display/CRMDOC/Using+Custom+Data+with+the+API</a>
  but couldn't get it to work.</p>
  
  <p>I can see the custom fields available here;
  SELECT * FROM <code>civicrm_value_attachments_52</code></p>
  
  <p>I can also see the entity_type for the case and file ID here:
  SELECT * FROM <code>civicrm_entity_file</code></p>
  
  <p>What query do I write to extract the attachment for a case or activity?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-10T10:05:51.660Z
Comments.Text: could you publish the api calls you tried, it should be fairly normal calls using the customvalue api
Comments.UserDisplayName: Xavier
Tags: <api><custom-fields>
Title: Custom Group and Fields using API v3
ThreadText: # Custom Group and Fields using API v3
  
  (Asked by: username_0 on 2015-08-10)
  
  I'm trying to query the API on CiviCRM 4.4.6 for a Custom Field (Attachment) on a Case and an Activity.
  
  I've tried the examples here: <http://wiki.civicrm.org/confluence/display/CRMDOC/Using+Custom+Data+with+the+API>
  but couldn't get it to work.
  
  I can see the custom fields available here;
  SELECT \* FROM `civicrm_value_attachments_52`
  
  I can also see the entity\_type for the case and file ID here:
  SELECT \* FROM `civicrm_entity_file`
  
  What query do I write to extract the attachment for a case or activity?
  
  **Tags:** api, custom-fields
  
  > **Comments:**
  > **username_1**: could you publish the api calls you tried, it should be fairly normal calls using the customvalue api  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2015-08-10. Score: 2 | Accepted answer
  
  you could try using the latest version of the [API explorer](http://dmaster.demo.civicrm.org/civicrm/api#explorer) to give you an idea of the API call. In general, if the custom field is attached to that entity you can just get it using the custom field number. The custom field number is the ID of the field, eg:
  
  ```
  $result = civicrm_api3('Case', 'get', array(
  'sequential' => 1,
  'return' => "custom_315",
  'id' => 1,
  ));
  
  ```
  
  or REST:
  
  ```
  /sites/all/modules/civicrm/extern/rest.php?entity=Case&action=get&api_key=yourkey&key=sitekey&json={"sequential":1,"return":"custom_13","id":1}
  
  ```
  
  > **Comments:**
  > **username_0**: One way with no results:  /civicrm/ajax/rest?entity=CustomValue&action=get&debug=1&sequential=1&json=1&entity_id=533&return.civicrm_value_attachments_52:file_upload_1_316=1&entity_id=533  {  "is_error":0,  "undefined_fields":["return_civicrm_value_attachments_52:file_upload_1_316"],  "version":3,  "count":0,  "values":[],  "xdebug":{   "peakMemory":41865784,   "memory":41708336,   "timeIndex":0.706025123596  } }  Tried this, but data not present in response: /civicrm/ajax/rest?entity=Case&action=get&debug=1&sequential=1&json=1&id=533&return=file_upload_1_316  No luck.  
  > **username_0**: Also tried (with and without custom_)  `code` /civicrm/ajax/rest?entity=Case&action=get&debug=1&sequential=1&json=1&id=533&return=custom_file_upload_1_316 `code`  with no luck and   `code` /civicrm/ajax/rest?entity=Case&action=get&debug=1&sequential=1&json=1&id=533&return.custom_file_upload_1_316=1 `code`  
  > **username_0**: Thanks @username_2. Still no results using your method with: /civicrm/ajax/rest?entity=Case&action=get&debug=1&sequential=1&json=1&id=533&return.custom_315=1 or /civicrm/ajax/rest?entity=Case&action=get&debug=1&sequential=1&json=1&id=533&return=custom_315  
  > **username_0**: Using the API docs explorer, it seems the field names are accurate: custom_316 File Upload 1 Case::Attachments File custom_317 File Upload 2 Case::Attachments File custom_318 File Upload 3 Case::Attachments File custom_319 File Upload 4 Case::Attachments File  
  > **username_0**: The following seems to return the file ID as 'latest'  /civicrm/ajax/rest?entity=CustomValue&action=get&debug=1&sequential=1&json=1&return.custom_316=1&entity_id=533  {  "is_error":0,  "undefined_fields":["return_custom_316"],  "version":3,  "count":1,  "id":316,  "values":[{   "entity_id":"533",   "latest":"39",   "id":"316",   "0":"39"  }],  "xdebug":{   "peakMemory":41831656,   "memory":41690848,   "timeIndex":0.714242935181  } }  I guess I'll have to use the ID to perform another query on the file itself using the ID. I would chain, but the explorer in this CiviCRM isn't up to the latest.  
  > **username_2**: I've added the syntax for the REST call to the answer, see if that works for you?  
  
  ---
  
  