CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Getting last modified date of a contact with an API call?
Pages: [1]

Author Topic: Getting last modified date of a contact with an API call?  (Read 1148 times)

jmickela

  • I post occasionally
  • **
  • Posts: 33
  • Karma: 0
  • CiviCRM version: 4.1.1
  • CMS version: Drupal 7
  • MySQL version: 5
  • PHP version: 5
Getting last modified date of a contact with an API call?
April 02, 2012, 06:55:07 pm
I've been looking for hours but can't find out how to use the API to get the last modified date of a contact. The answer must be fairly straightforward as this is a pretty standard thing to output.

How would I get this data?

bouton

  • Guest
Re: Getting last modified date of a contact with an API call?
April 03, 2012, 02:54:03 am
There was this
http://forum.civicrm.org/index.php?topic=22774.0
but I have yet to be able to get it to work.
If you are more successful, please post your answer - thanks

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Getting last modified date of a contact with an API call?
April 03, 2012, 04:09:34 am
It seems a rather common need, but so far no easy API to access it.

Most of developers are going to be in a code sprint this week. If you plan to work on implementing the API for it, jumping on IRC would be the right moment to do it (US west coast TZ)

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

jmickela

  • I post occasionally
  • **
  • Posts: 33
  • Karma: 0
  • CiviCRM version: 4.1.1
  • CMS version: Drupal 7
  • MySQL version: 5
  • PHP version: 5
Re: Getting last modified date of a contact with an API call?
April 03, 2012, 03:12:58 pm
I did the following in a Drupal module. I don't really have time to learn how to implement this in the CiviCRM API, but this may help you get the modified date for an entity.


Quote
$r = db_query("SELECT modified_date FROM {civicrm_log} WHERE entity_table = 'civicrm_contact' AND entity_id = {$row['contact_id']} ORDER BY modified_date DESC");
            
foreach($r as $record)
{
   print_r($record);
}

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Getting last modified date of a contact with an API call?
April 03, 2012, 03:42:50 pm
Not sure if you are not open to sql injection (your code looks like it), and you seem to do one query per row and return all the modifications date, not only the last one (bad performance)

The easiest is probably to get the list of all the contact ids and do a single query (sort of doing a proper join in the main query).


so for api/v3/Contact.php civicrm_api3_contact_get
if the param return contains modified_date, fetch the contacts, create an array with the ids, run this query

Code: [Select]
select entity_id,max(modified_date) from civicrm_log where entity_table = 'civicrm_contact' and entity_id in (1,2,3,4,5) group by entity_id
and add the modified_date in each of the contact arrays before returning it.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Getting last modified date of a contact with an API call?

This forum was archived on 2017-11-26.