2

when I attempt to import historical data to seed the CRM, created_date is ignored and today's date/time is used instead. Using the API explorer, it looks like the date should be saved, but, when I do a subsequent get, it has today's date:

https://somewhere.com/sites/all/modules/civicrm/extern/rest.php?entity=Contact&action=create&api_key=userkey&key=sitekey&json={"contact_type":"Individual","created_date":"2018-01-01","first_name":"Peteww"}

returns: {

"is_error": 0,
"version": 3,
"count": 1,
"id": 288,
"values": {
    "288": {
        "id": "288",
        "contact_type": "Individual",
        "contact_sub_type": "",
        "do_not_email": "",
        "do_not_phone": "",
        "do_not_mail": "",
        "do_not_sms": "",
        "do_not_trade": "",
        "is_opt_out": "",
        "legal_identifier": "",
        "external_identifier": "",
        "sort_name": "Peteww",
        "display_name": "Peteww",
        "nick_name": "",
        "legal_name": "",
        "image_URL": "",
        "preferred_communication_method": "",
        "preferred_language": "en_CA",
        "preferred_mail_format": "",
        "hash": "74c74a58f64681a6e3a4f8d9ccd32bfd",
        "api_key": "",
        "first_name": "Peteww",
        "middle_name": "",
        "last_name": "",
        "prefix_id": "",
        "suffix_id": "",
        "formal_title": "",
        "communication_style_id": "1",
        "email_greeting_id": "1",
        "email_greeting_custom": "",
        "email_greeting_display": "",
        "postal_greeting_id": "1",
        "postal_greeting_custom": "",
        "postal_greeting_display": "",
        "addressee_id": "1",
        "addressee_custom": "",
        "addressee_display": "",
        "job_title": "",
        "gender_id": "",
        "birth_date": "",
        "is_deceased": "",
        "deceased_date": "",
        "household_name": "",
        "primary_contact_id": "",
        "organization_name": "",
        "sic_code": "",
        "user_unique_id": "",
        "created_date": "20180101000000",
        "modified_date": ""
    }
}

}

but when I do:

https://somewhere.com/sites/all/modules/civicrm/extern/rest.php?entity=Contact&action=get&api_key=userkey&key=sitekey&json={"sequential":1,"return":"created_date","id":288}

I get: {

"is_error": 0,
"version": 3,
"count": 1,
"id": 288,
"values": [
    {
        "contact_id": "288",
        "created_date": "2019-04-15 18:00:01",
        "id": "288"
    }
]

}

4

Mike,

Unfortunately you can't set created_date in create api of Contact since there is a trigger which will over-ride your created_date value

DELIMITER $$
CREATE TRIGGER `civicrm_contact_before_insert` BEFORE INSERT ON `civicrm_contact` FOR EACH ROW BEGIN  
SET NEW.created_date = CURRENT_TIMESTAMP;
 END
$$
DELIMITER ;

Either you can delete this trigger or update the contact using same api by passing contact id to set created_date after its been created

https://somewhere.com/sites/all/modules/civicrm/extern/rest.php?entity=Contact&action=create&api_key=userkey&key=sitekey&json={"contact_type":"Individual","last_name":"test","first_name":"Peteww"}

https://somewhere.com/sites/all/modules/civicrm/extern/rest.php?entity=Contact&action=create&api_key=userkey&key=sitekey&json={"id":"288","created_date":"2018-01-01"}

Thanks

  • great, thanks! I'll probably opt to update after its created, since I don't want to affect contact creation via the CRM. – Mike Stairs Apr 16 at 20:02
  • So can you mark this as answered if it worked foryou? – Pradeep Nayak Apr 16 at 20:03
  • 1
    please! Is there a way to do it myself in the future? – Mike Stairs Apr 17 at 13:37
  • To mark an answer as accepted, click on the check mark beside the answer to toggle it from greyed out to filled in. (stackoverflow.com/help/someone-answers) – Pradeep Nayak Apr 17 at 13:50

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.