2

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?

  • could you publish the api calls you tried, it should be fairly normal calls using the customvalue api – Xavier Aug 10 '15 at 10:05
2

you could try using the latest version of the 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}
  • 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. – Adam Aug 10 '15 at 10:18
  • 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 – Adam Aug 10 '15 at 10:20
  • 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 – Adam Aug 10 '15 at 10:34
  • 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 – Adam Aug 10 '15 at 10:38
  • 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. – Adam Aug 10 '15 at 10:43

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.