Jump to content


srmt

Member Since 01 Oct 2012
Offline Last Active Oct 08 2012 07:19 AM
-----

Posts I've Made

In Topic: csv import problem

02 October 2012 - 02:20 PM

I can't find a way by calling rest api only once. My code calls the api as much as record count in csv file so it works very slowly. What can i do?

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
include 'resthelper.php';
$username = 'super';
$password = '1234';
$authenticationData = login($username, $password);
require_once("File_CSV_DataSource-1.0.1/DataSource.php");
// usage sample
 
createUser($authenticationData);
 
function login($username2, $password2)
{
  $headers = array(
   'Accept: application/json',
   'ZURMO_AUTH_USERNAME: ' . $username2,
   'ZURMO_AUTH_PASSWORD: ' . $password2,
   'ZURMO_API_REQUEST_TYPE: REST',
   );
  $response = ApiRestHelper::createApiCall('http://localhost/zurmo/app/index.php/zurmo/api/login', 'POST', $headers);
  $response = json_decode($response, true);
  if ($response['status'] == 'SUCCESS')
  {
   //ob_start();
   session_start();
   echo "<br />sessionId : " . $response['data']['sessionId'] . "<br />";
   echo "token : " . $response['data']['token'] . "<br />";
   $_SESSION['sessionId'] = $response['data']['sessionId'];
   $_SESSION['token'] = $response['data']['token'];
   return $response['data'];
   // header( 'Location: getuser.php' ) ;
  }
  else
  {
		 //return false;
   header( 'Status: 404 Not Found' ) ;
  }
}
function createUser($authenticationData)
{
  $accounts = array();
  require_once("File_CSV_DataSource-1.0.1/DataSource.php");
  // usage sample
  $csv = new File_CSV_DataSource;
  if ($csv->load('./zurmo.csv')) {
   if ($csv->isSymmetric()) {
	$array = $csv->connect();
   }else{
	// fetch records that dont match headers length
	$array = $csv->getAsymmetricRows();
   }
  
  $headers = array(
   'Accept: application/json',
   'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'],
   'ZURMO_TOKEN: ' . $authenticationData['token'],
   'ZURMO_API_REQUEST_TYPE: REST',
   );
  
   foreach($array as $account){
  $data = array(
   'name' => $account['zurmo'],
   );
  
   $response = ApiRestHelper::createApiCall('http://localhost/zurmo/app/index.php/accounts/account/api/create/', 'POST',
   $headers, array('data' => $data));
  // Decode json data
  $response = json_decode($response, true);
  if ($response['status'] == 'SUCCESS')
  {
   $user = $response['data'];
	  //Do something with user
   echo "<br/>createUser SUCCESS<br/>";
   //print_r($response);
   echo "<br/>id : " . $user['id'];
  }
  else
  {
	  // Error, for example if we provided invalid user id
   $errors = $response['errors'];
	  // Do something with errors
   echo "<br/>createUser ERROR<br/>";
   print_r($response);
 
  }//if end
 
}//foreach end
 
}//csv end
 
}//function end
 
?>

In Topic: csv import problem

01 October 2012 - 11:32 AM

i have another question. In salesforce we can parse data by using code like this :

try {
$mySforceConnection = new SforceEnterpriseClient();
$mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/enterprisewsdl.xml');
$mylogin = $mySforceConnection->login("username", "Pass");
} catch (Exception $e) {
print_r($e);
exit();
}
$account = new stdclass();
$account->Name = "Billy"; // we can put data that we parsed csv file
$account->BillingCity = "London";
$mySforceConnection->create($account,'Account');

Is there a similar way for zurmo?

In Topic: csv import problem

01 October 2012 - 11:20 AM

I updated osx to 10.8.2 and tried your demo instance but same problem has occured.

In Topic: csv import problem

01 October 2012 - 10:08 AM

Chrome : 22.0.1229.79 Osx: 10.8

In Topic: csv import problem

01 October 2012 - 09:00 AM

Google Chrome doesn't support import module of zurmo but safari and firefox works perfectly.