In our previous article, We discussed about the migrating users from websites to online community using CSV import. This solution is relevant only if you want to migrate users for one time but this solution won’t work if you want to keep synchronize user data between the systems. We encounter this issue with one of our client “The Science Advisory Board ” who was using Qualtrics system for their survey and using socielengine for online community. They have ~1 million users in the qualtircs system and while 90 thousands of users belong to socialengine community. Users changes their personal data in both systems and we need to synchronize them. We recommended our client a solution to automate the qualtrics user synchronization using custom plugin built on socialengine
Implementing synchronization between socialengine and Qualtrics
We made two strategies in order to resolve user synchronization problem. First strategy was to synchronize the data on the daily basis so whenever there is a change in the record in one system then modified data is updated on the both systems. So approach to create full synchronization which update every data in both systems.
Pulling and pushing user data
In Both strategy we need to fetch data from qualtrics system and compare the data with socialengine. So if the data is modified on socialengine then we would need to push the latest data in qualtrics. Now we are going to describe the solution to resolve this problem in details.
- Pull Contact from Qualtrics : We used “getDirectoryContacts” api call from qualtrics to get contacts. So each contact have two cases, Either they were updated in socialengine or updated in qualtrics so we have handle both cases.
Step 1 : Get the user contacts using qualtrics api
$values['apipath']= $settings->getSetting('datasync.api.path', "https://survey.qualtrics.com/WRAPI/Contacts/api.php"); ......... ......... $options = array('adapter' => 'Zend_Http_Client_Adapter_Curl',); // Create an adapter object and attach it to the HTTP client $client = new Zend_Http_Client($values['apipath']); $client->setParameterGet("Request","getDirectoryContacts"); $client->setParameterGet("User",$bioinfo_api_user); $client->setParameterGet("Token",$token); $client->setParameterGet("Format","JSON"); ..........
Step 2.a : if contact exists in SAB then update contact in SAB
public function updateToSE($contacts) { ............... ............... foreach ( $contact as $outerKeys => $outerValues ) { $field_id = - 1; $option_id = - 1; $type = - 1; if (array_key_exists ( $outerKeys . "_" . $outerValues, $mapTAtoSE ) && ! empty ( $userId ) && ! empty ( $outerValues )) { $field_id = $mapTAtoSE [$outerKeys . "_" . $outerValues] ['se_field_id']; $option_id = $mapTAtoSE [$outerKeys . "_" . $outerValues] ['se_option_id']; $type = $mapTAtoSE [$outerKeys . "_" . $outerValues] ['meta_type']; ................ }
Step 2.b : else create contact in SAB.
public function createToSE($contact) { .............. .......................... $enabled = 1; $timezone = $settings->getSetting ( 'core.locale.timezone', 'America/Los_Angeles' ); $locale = $settings->getSetting ( 'core.locale.locale', 'auto' ); $language = $settings->getSetting ( 'core.locale.language', 'en_US' ); // $creation_ip = '2791763097'; $salt = ( string ) rand ( 1000000, 9999999 ); $salt1 = Engine_Api::_ ()->getApi ( 'settings', 'core' )->getSetting ( 'core.secret', 'staticSalt' ); $incrypt_password = md5 ( $salt1 . 'admin' . $salt ); $new_user_id = $userTable->insert ( array ( 'user_id' => null, 'email' => $email, //'username' => str_replace ( ' ', '', $user_name ), 'displayname' => $displayname, 'password' => $incrypt_password, ....................... }
- Push contact to Qualtrics : We used Get all “updateContact” api and “createContact” api from qualtrics .So each contact have two cases, Either they were updated in qualtrics or created in qualtrics so we have handle both cases.
Step 1: Look at the contact in qualtrics if exists then update into qualtrics
.................... ................... $client = new Zend_Http_Client($values['apipath']); $client->setParameterPost("Request","updateContact"); $client->setParameterPost("User",$bioinfo_api_user); $client->setParameterPost("Token",$token); $client->setParameterPost("Format","JSON"); $client->setParameterPost("Version","2.3"); ........................ ............... $request = $client->request('POST'); $response = $request->getBody(); //$response = $client->request()->getBody(); $data = Zend_Json::decode($response);
Step 2 : Else Create contact in qualtrics
......................... ......................... $client = new Zend_Http_Client($values['apipath']); $client->setParameterPost("Request","createContact"); $client->setParameterPost("User",$bioinfo_api_user); $client->setParameterPost("Token",$token); $client->setParameterPost("Format","JSON"); $client->setParameterPost("Version","2.3"); ........................ .......................... ................ if(!empty($userKeyArray) && $userKeyArray != "email") { // updating segments in to TA if(array_key_exists($userKeyArray,$otherArray)) { $client->setParameterPost("ED[$userKeyArray]",$userValueArray); } else{ $client->setParameterPost("ED[$userKeyArray]",implode("/",$userValueArray)); }}else{ $client->setParameterPost("ED[$userKeyArray]","/"); }
This blog is going to help you in migrate users information between qualtrics and socialengine. We have been synchronizing thousands of user on daily basis using socialengine task scheduling. Feel free to contact us if you have any further queries.