如何使用RESTAPI从sugarcrm获取所有帐户记录,包括已删除的记录

如何使用RESTAPI从sugarcrm获取所有帐户记录,包括已删除的记录,rest,sugarcrm,accounts,Rest,Sugarcrm,Accounts,下面是我使用RESTAPI从sugarcrm获取帐户模块结果的代码 我想获取所有记录,包括已删除的记录,但它只抛出已删除或未删除的帐户。但我需要两种类型的记录使用一个请求请帮助 $url = "http://localhost/SugarCRM/service/v4/rest.php"; $username = "admin"; $password = "1234"; //function to make cURL request function call($method, $paramet

下面是我使用RESTAPI从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>';
$url=”http://localhost/SugarCRM/service/v4/rest.php";
$username=“admin”;
$password=“1234”;
//函数发出卷曲请求
函数调用($method,$parameters,$url)
{
ob_start();
$curl\u request=curl\u init();
curl_setopt($curl_请求,CURLOPT_URL,$URL);
curl_setopt($curl_request,CURLOPT_POST,1);
curl\u setopt($curl\u请求,curl\u HTTP\u版本,curl\u HTTP\u版本1\u 0);
curl_setopt($curl_请求,CURLOPT_头,1);
curl\u setopt($curl\u请求,CURLOPT\u SSL\u验证对等,0);
curl_setopt($curl_请求,CURLOPT_返回传输,1);
curl_setopt($curl_请求,CURLOPT_FOLLOWLOCATION,0);
$jsonEncodedData=json_encode($parameters);
$post=数组(
“方法”=>$method,
“输入类型”=>“JSON”,
“响应类型”=>“JSON”,
“rest_数据”=>$jsonEncodedData
);
curl_setopt($curl_request,CURLOPT_POSTFIELDS,$post);
$result=curl\u exec($curl\u request);
卷曲关闭($curl\u请求);
$result=explode(“\r\n\r\n”,$result,2);
$response=json_decode($result[1]);
ob_end_flush();
返回$response;
}
//登录--------------------------------------------
$login\u参数=数组(
“用户身份验证”=>数组(
“用户名”=>$username,
“密码”=>md5($password),
“版本”=>“1”
),
“应用程序名称”=>“RestTest”,
“名称\u值\u列表”=>array(),
);
$login\u result=call(“login”,$login\u参数,$url);
/*
回声“;
打印(登录结果);
回声“;
*/
//获取会话id
$session\u id=$login\u result->id;
$current_date='2014-06-30'//日期(“Y-m-d”);
//获取记录列表--------------------------------
$get\u entry\u list\u参数=数组(
//会话id
“会话”=>$session\u id,
//要从中检索记录的模块的名称
“模块名称”=>“账户”,
//不带单词“WHERE”的SQL WHERE子句。
'查询'=>“(accounts.deleted='0'或accounts.deleted='1')和日期(accounts.DATE\u entered)='$current\u DATE',
//SQL ORDER BY子句中没有短语“ORDER BY”。
“订单依据”=>“”,
//要从其开始的记录偏移量。
“偏移量”=>“0”,
//可选。要包含在结果中的字段列表。
“选择_字段”=>数组(
“id”,
“姓名”,
“账单地址街”,
“账单地址城市”,
“账单地址邮政编码”,
“账单地址国家”,
“船运地址街”,
“发货地址城市”,
“发货地址邮政编码”,
“装运地址国家”,
"网站",,
“已删除”,
),
/*
链接名称列表以及每个链接名称要返回的字段。
示例:“链接\u名称\u到\u字段\u数组”=>数组(数组('name'=>'email\u address','value'=>数组('id','email\u address','opt\u out','primary\u address'))
*/
“链接\u名称\u到\u字段\u数组”=>数组(
),
//要返回的最大结果数。
“最大结果”=>“”,
//排除已删除记录的步骤
//“已删除”=>false,
//如果只返回标记为收藏夹的记录。
//“收藏夹”=>错误,
);
$get\u entry\u list\u result=调用($get\u entry\u list',$get\u entry\u list\u参数,$url);
回声';
打印($get\u entry\u list\u result);
回声';

我建议不要使用查询部分,只需取消注释并将“deleted”=>设置为true,我使用的是API的4_1版本,这对我很有用

默认值很可能为false,并且您的查询被它覆盖


希望这有帮助

如果我将'deleted'=>设置为true,那么它只显示已删除的记录,但我需要同时删除和激活这两个记录