AnsweredAssumed Answered

API - Get record's information with an email (filter on link)

Question asked by Groupe Sugar on Apr 27, 2017
Latest reply on Sep 13, 2017 by hats

Hello, I am struggling a bit with SugarCRM v7 API.

 

Actually, I am trying to retrieve an Account ID with his email in parameter.
I'm doing the following thing : 

 

$url = $base_url. "/Accounts";

$curl_request = curl_init($url);
curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($curl_request, CURLOPT_HEADER, false);
curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_request, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($curl_request, CURLOPT_HTTPHEADER, array(
   "Content-Type: application/json",
   "oauth-token: {$oauth_token}"
));

 

$filter_arguments = array(
   "filter" => array(
      array(
         "email" => array( '$eq'=>'test@test.com'),
      ),
   ),
   "link_name"=>"email",
   "max_num" => 200,
   "offset" => 0,
   "fields" => "email,name,id",
   "order_by" => "email:DESC",
   "favorites" => false,
   "my_items" => false,
);

 

//convert arguments to json
$json_arguments = json_encode($filter_arguments);
curl_setopt($curl_request, CURLOPT_POSTFIELDS, $json_arguments);

 

//execute request
$curl_response = curl_exec($curl_request);

 

//decode json
$res = json_decode($curl_response);

 

//display the created record
echo "<pre>";
print_r($res);
echo "</pre>";
curl_close($curl_request);

 

The appropriate result would be to retrieve a record having an email equals to 'test@test.com'

 

Have you got any idea about what I'm doing wrong ?

 

Best regards,
Bastien

Outcomes