I am calling the Drupal API "user_save" to create a brand new Drupal user. This does create a new Drupal user. But this user does not have the CiviCRM first name or last name fields set. How can I pass first name and last name to the Drupal API "user_save"?
I investigated how CiviCRM handles passing the firstname and last name when someone registers online (which includes a profile that collects first name and last name). CiviCRM only has a mechanism to deal with this situation when someone is online, not using the API, per code in the CiviCRM core file /sites/all/modules/civicrm/drupal/civicrm_user.inc
This issue causes problems with my CiviCRM dedup rule, which is set to check for first name, last name and email. Since for any Drupal user created via the API does not pass the first name or last name, a new CiviCRM contact is created as well. (In addition to the Drupal user)
In my scenario I have a civicrm contact called "testfirst", "testlast", "firstname.lastname@example.org" in the backoffice. I create a Drupal user for this contact (using the API user_save). This contact does get associated with the new Drupal user. However, there is also a brand new contact with the email address "email@example.com" but no other data. This brand new contact is getting created because the unsupervised dedup rule is checking for all 3 fields (first name, last name, and email).