2014-06-30 78 views
1

以下是我的代碼從sugarcrm使用rest api獲取帳戶模塊的結果 我想獲取所有記錄,包括已刪除的一個,但它只拋出刪除或非已刪除的帳戶。但我需要用一個請求兩個類型的記錄,請幫助如何獲取所有帳戶記錄,包括使用REST api從sugarcrm中刪除的記錄

$url = "http://localhost/SugarCRM/service/v4/rest.php"; 
$username = "admin"; 
$password = "1234"; 

//function to make cURL request 
function call($method, $parameters, $url) 
{ 
    ob_start(); 
    $curl_request = curl_init(); 

    curl_setopt($curl_request, CURLOPT_URL, $url); 
    curl_setopt($curl_request, CURLOPT_POST, 1); 
    curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 
    curl_setopt($curl_request, CURLOPT_HEADER, 1); 
    curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($curl_request, CURLOPT_FOLLOWLOCATION, 0); 

    $jsonEncodedData = json_encode($parameters); 

    $post = array(
     "method" => $method, 
     "input_type" => "JSON", 
     "response_type" => "JSON", 
     "rest_data" => $jsonEncodedData 
    ); 

    curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post); 
    $result = curl_exec($curl_request); 
    curl_close($curl_request); 

    $result = explode("\r\n\r\n", $result, 2); 
    $response = json_decode($result[1]); 
    ob_end_flush(); 

    return $response; 
} 

//login -------------------------------------------- 

$login_parameters = array(
    "user_auth"=>array(
      "user_name"=>$username, 
      "password"=>md5($password), 
      "version"=>"1" 
    ), 
    "application_name"=>"RestTest", 
    "name_value_list"=>array(), 
); 

$login_result = call("login", $login_parameters, $url); 

/* 
echo "<pre>"; 
print_r($login_result); 
echo "</pre>"; 
*/ 

//get session id 
$session_id = $login_result->id; 
$current_date='2014-06-30';//date('Y-m-d'); 

//get list of records -------------------------------- 

$get_entry_list_parameters = array(

    //session id 
    'session' => $session_id, 

    //The name of the module from which to retrieve records 
    'module_name' => 'Accounts', 

    //The SQL WHERE clause without the word "where". 
    'query' => "(accounts.deleted='0' or accounts.deleted='1') AND DATE(accounts.date_entered)='$current_date'", 

    //The SQL ORDER BY clause without the phrase "order by". 
    'order_by' => "", 

    //The record offset from which to start. 
    'offset' => '0', 

    //Optional. A list of fields to include in the results. 
    'select_fields' => array(
      'id', 
      'name', 
      'billing_address_street', 
      'billing_address_city', 
      'billing_address_postalcode', 
      'billing_address_country', 
      'shipping_address_street', 
      'shipping_address_city', 
      'shipping_address_postalcode', 
      'shipping_address_country', 
      'website', 
      'deleted', 
    ), 

    /* 
    A list of link names and the fields to be returned for each link name. 
    Example: 'link_name_to_fields_array' => array(array('name' => 'email_addresses', 'value' => array('id', 'email_address', 'opt_out', 'primary_address'))) 
    */ 
    'link_name_to_fields_array' => array(
    ), 

    //The maximum number of results to return. 
    'max_results' => '', 

    //To exclude deleted records 
    //'deleted' => false, 

    //If only records marked as favorites should be returned. 
    //'Favorites' => false, 
); 

$get_entry_list_result = call('get_entry_list', $get_entry_list_parameters, $url); 

echo '<pre>'; 
print_r($get_entry_list_result); 
echo '</pre>'; 

回答

1

我建議不使用查詢部分,只是取消註釋並設置「刪除」 =>真的,我現在用的是API的4_1版本和作品爲了我。

這很可能是默認值爲false並且您的查詢被覆蓋。

希望幫助

+0

如果我設置「刪除」 => true,那麼它是隻顯示已刪除的記錄,但我需要兩個刪除,welll爲活動 – user3789579

相關問題