Answers.Body: <p>Mike,</p>
  
  <p>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</p>
  
  <pre><code>DELIMITER $$
  CREATE TRIGGER `civicrm_contact_before_insert` BEFORE INSERT ON `civicrm_contact` FOR EACH ROW BEGIN  
  SET NEW.created_date = CURRENT_TIMESTAMP;
   END
  $$
  DELIMITER ;
  </code></pre>
  
  <p>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</p>
  
  <pre><code>https://somewhere.com/sites/all/modules/civicrm/extern/rest.php?entity=Contact&amp;action=create&amp;api_key=userkey&amp;key=sitekey&amp;json={"contact_type":"Individual","last_name":"test","first_name":"Peteww"}
  
  https://somewhere.com/sites/all/modules/civicrm/extern/rest.php?entity=Contact&amp;action=create&amp;api_key=userkey&amp;key=sitekey&amp;json={"id":"288","created_date":"2018-01-01"}
  </code></pre>
  
  <p>Thanks</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-16T20:02:00.197Z
Answers.Text: great, thanks! I'll probably opt to update after its created, since I don't want to affect contact creation via the CRM.
Answers.UserDisplayName: Mike Stairs
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-16T20:03:21.470Z
Answers.Text: So can you mark this as answered if it worked foryou?
Answers.UserDisplayName: Pradeep Nayak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-17T13:37:32.577Z
Answers.Text: please! Is there a way to do it myself in the future?
Answers.UserDisplayName: Mike Stairs
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-17T13:50:24.140Z
Answers.Text: To mark an answer as accepted, click on the check mark beside the answer to toggle it from greyed out to filled in. (https://stackoverflow.com/help/someone-answers)
Answers.UserDisplayName: Pradeep Nayak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-16T10:11:31.217Z
Answers.LastActivityDate: 2019-04-16T10:11:31.217Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>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:</p>
  
  <p><a href="https://somewhere.com/sites/all/modules/civicrm/extern/rest.php?entity=Contact&amp;action=create&amp;api_key=userkey&amp;key=sitekey&amp;json=" rel="nofollow noreferrer">https://somewhere.com/sites/all/modules/civicrm/extern/rest.php?entity=Contact&amp;action=create&amp;api_key=userkey&amp;key=sitekey&amp;json=</a>{"contact_type":"Individual","created_date":"2018-01-01","first_name":"Peteww"}</p>
  
  <p>returns:
  {</p>
  
  <pre><code>"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": ""
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>but when I do:</p>
  
  <p><a href="https://somewhere.com/sites/all/modules/civicrm/extern/rest.php?entity=Contact&amp;action=get&amp;api_key=userkey&amp;key=sitekey&amp;json=" rel="nofollow noreferrer">https://somewhere.com/sites/all/modules/civicrm/extern/rest.php?entity=Contact&amp;action=get&amp;api_key=userkey&amp;key=sitekey&amp;json=</a>{"sequential":1,"return":"created_date","id":288}</p>
  
  <p>I get:
  {</p>
  
  <pre><code>"is_error": 0,
  "version": 3,
  "count": 1,
  "id": 288,
  "values": [
      {
          "contact_id": "288",
          "created_date": "2019-04-15 18:00:01",
          "id": "288"
      }
  ]
  </code></pre>
  
  <p>}</p>
  
Tags: <api>
Title: Why is date_created field is ignored for Contact creation via API?
ThreadText: # Why is date_created field is ignored for Contact creation via API?
  
  (Asked by: username_0 on 2019-04-15)
  
  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"
      }
  ]
  
  }
  
  **Tags:** api
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-04-16. Score: 4 | Accepted answer
  
  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
  
  > **Comments:**
  > **username_0**: great, thanks! I'll probably opt to update after its created, since I don't want to affect contact creation via the CRM.  
  > **username_1**: So can you mark this as answered if it worked foryou?  
  > **username_0**: please! Is there a way to do it myself in the future?  
  > **username_1**: To mark an answer as accepted, click on the check mark beside the answer to toggle it from greyed out to filled in. (https://stackoverflow.com/help/someone-answers)  
  
  ---
  
  