Answers.Body: <p>We believe the bug may be caused by the Drupal hook model which expects to receive Drupal form data which the Civi API is not capable of invoking since, of course, it does not use forms. Shimming the data would have been messy and clunky so in the end we hooked directly into the LDAP module using CiviCRM's edit hooks. Like this:</p>
  
  <pre><code>function ldap_user_civicrm_post($op, $objectName, $objectId, &amp;$objectRef) {
    if ($op=="edit") {
      try {
        $cms_user_id = civicrm_api3('UFMatch', 'getvalue', array(
          'return' =&gt; "uf_id",
          'contact_id' =&gt; $objectId,
        ));
        if ($cms_user_id) {
          $account = user_load($cms_user_id);
  
          $ldap_user_conf = ldap_user_conf();
  
          $bool_result = $ldap_user_conf-&gt;synchToLdapEntry($account);
          if ($bool_result) {
            ldap_user_ldap_provision_semaphore('synch', 'set', $account-&gt;name);
          }
        }
      } catch (Exception $e) {
  
      }
    }
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-19T10:22:22.460Z
Answers.LastActivityDate: 2016-07-19T10:22:22.460Z
Answers.UserDisplayName: DMCoding
Body: <p>We're trying to push a Civi contact's data into an LDAP data store using the Civi Drupal entity module and the Drupal ldap module. That part works fine. If a user updates their contact card using a Civi user profile form, the changes are immediately pushed into ldap. </p>
  
  <p>But when we update the same contact using the Rest API, the changes are not synced into ldap and we dont know why. (The REST API call does successfully update the civi contact card however.) We suspect its because some specific Drupal function is not being called and are wondering if it is a bug. The closest I have been able to find is <code>hook_user_update</code>. Reading the documentation, we believe it isn't called by the Rest API but is called by Civi Profile form. We're not sure about this.</p>
  
  <p>What can we do to ensure that the Civi entity module successfully updates our LDAP store when called using the REST interface?</p>
  
Tags: <api><profile><tokens><civicrm-entity><rest>
Title: Suspected external REST API not updating Drupal entities
ThreadText: # Suspected external REST API not updating Drupal entities
  
  (Asked by: username_0 on 2016-07-11)
  
  We're trying to push a Civi contact's data into an LDAP data store using the Civi Drupal entity module and the Drupal ldap module. That part works fine. If a user updates their contact card using a Civi user profile form, the changes are immediately pushed into ldap.
  
  But when we update the same contact using the Rest API, the changes are not synced into ldap and we dont know why. (The REST API call does successfully update the civi contact card however.) We suspect its because some specific Drupal function is not being called and are wondering if it is a bug. The closest I have been able to find is `hook_user_update`. Reading the documentation, we believe it isn't called by the Rest API but is called by Civi Profile form. We're not sure about this.
  
  What can we do to ensure that the Civi entity module successfully updates our LDAP store when called using the REST interface?
  
  **Tags:** api, profile, tokens, civicrm-entity, rest
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2016-07-19. Score: 1 | Accepted answer
  
  We believe the bug may be caused by the Drupal hook model which expects to receive Drupal form data which the Civi API is not capable of invoking since, of course, it does not use forms. Shimming the data would have been messy and clunky so in the end we hooked directly into the LDAP module using CiviCRM's edit hooks. Like this:
  function ldap_user_civicrm_post($op, $objectName, $objectId, &$objectRef) {
    if ($op=="edit") {
      try {
        $cms_user_id = civicrm_api3('UFMatch', 'getvalue', array(
          'return' => "uf_id",
          'contact_id' => $objectId,
        ));
        if ($cms_user_id) {
          $account = user_load($cms_user_id);
  
          $ldap_user_conf = ldap_user_conf();
  
          $bool_result = $ldap_user_conf->synchToLdapEntry($account);
          if ($bool_result) {
            ldap_user_ldap_provision_semaphore('synch', 'set', $account->name);
          }
        }
      } catch (Exception $e) {
  
      }
    }
  }
  
  
  ---
  
  