id
stringlengths 14
16
| text
stringlengths 33
5.27k
| source
stringlengths 105
270
|
---|---|---|
3512510b0cd9-4 | (
[name] => user_number_seperator
[value] => ,
)
[user_decimal_seperator] => stdClass Object
(
[name] => user_decimal_seperator
[value] => .
)
[mobile_max_list_entries] => stdClass Object
(
[name] => mobile_max_list_entries
[value] => 10
)
[mobile_max_subpanel_entries] => stdClass Object
(
[name] => mobile_max_subpanel_entries
[value] => 3
)
[user_currency_name] => stdClass Object
(
[name] => user_currency_name
[value] => US Dollars
)
)
)
Â
Last modified: 2023-02-03 21:09:36 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Logging_In/index.html |
9e3bf36e16d2-0 | This API has been succeeded by a new version. It is recommended to upgrade to the latest API.
Retrieving a List of Records With Related Info
Overview
A PHP example demonstrating how to retrieve a list of records with info from a related entity with the get_entry_list method using cURL and the v4_1 REST API.
This example will retrieve a list of contacts and their related email addresses.
Example
<?php
$url = "http://{site_url}/service/v4_1/rest.php";
$username = "admin";
$password = "password";
//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]); | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_a_List_of_Records_With_Related_Info/index.html |
9e3bf36e16d2-1 | $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;
//retrieve records -------------------------------------
$get_entry_list_parameters = array(
//session id
'session' => $session_id,
//The name of the module from which to retrieve records
'module_name' => "Contacts",
//The SQL WHERE clause without the word "where".
'query' => "",
//The SQL ORDER BY clause without the phrase "order by".
'order_by' => "",
//The record offset from which to start.
'offset' => "0",
//Optional. The list of fields to be returned in the results
'select_fields' => array(
'id',
'first_name',
'last_name',
),
//A list of link names and the fields to be returned for each link name
'link_name_to_fields_array' => array(
array(
'name' => 'email_addresses',
'value' => array(
'id',
'email_address', | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_a_List_of_Records_With_Related_Info/index.html |
9e3bf36e16d2-2 | 'value' => array(
'id',
'email_address',
'opt_out',
'primary_address'
),
),
),
//The maximum number of results to return.
'max_results' => '2',
//To exclude deleted records
'deleted' => 0,
//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>";
?>
Result
stdClass Object
(
[result_count] => 2
[total_count] => 200
[next_offset] => 2
[entry_list] => Array
(
[0] => stdClass Object
(
[id] => 116d9bc6-4a24-b826-952e-4f7cb6b25ea7
[module_name] => Contacts
[name_value_list] => stdClass Object
(
[id] => stdClass Object
(
[name] => id
[value] => 116d9bc6-4a24-b826-952e-4f7cb6b25ea7
)
[first_name] => stdClass Object
(
[name] => first_name
[value] => Lucinda
)
[last_name] => stdClass Object
(
[name] => last_name
[value] => Jacoby
)
)
)
[1] => stdClass Object
( | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_a_List_of_Records_With_Related_Info/index.html |
9e3bf36e16d2-3 | )
)
)
[1] => stdClass Object
(
[id] => 11c263ef-ff61-71ff-f090-4f7cb6fc9f68
[module_name] => Contacts
[name_value_list] => stdClass Object
(
[id] => stdClass Object
(
[name] => id
[value] => 11c263ef-ff61-71ff-f090-4f7cb6fc9f68
)
[first_name] => stdClass Object
(
[name] => first_name
[value] => Ike
)
[last_name] => stdClass Object
(
[name] => last_name
[value] => Gassaway
)
)
)
)
[relationship_list] => Array
(
[0] => stdClass Object
(
[link_list] => Array
(
[0] => stdClass Object
(
[name] => email_addresses
[records] => Array
(
[0] => stdClass Object
(
[link_value] => stdClass Object
(
[id] => stdClass Object
(
[name] => id
[value] => 13066f13-d6ea-405c-0f95-4f7cb6fa3a08
)
[email_address] => stdClass Object
(
[name] => email_address
[value] => support52@example.org
)
[opt_out] => stdClass Object
(
[name] => opt_out
[value] => 0
) | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_a_List_of_Records_With_Related_Info/index.html |
9e3bf36e16d2-4 | [name] => opt_out
[value] => 0
)
[primary_address] => stdClass Object
(
[name] => primary_address
[value] =>
)
)
)
[1] => stdClass Object
(
[link_value] => stdClass Object
(
[id] => stdClass Object
(
[name] => id
[value] => 13e3d111-b226-c363-4832-4f7cb699a3a0
)
[email_address] => stdClass Object
(
[name] => email_address
[value] => qa.section@example.it
)
[opt_out] => stdClass Object
(
[name] => opt_out
[value] => 1
)
[primary_address] => stdClass Object
(
[name] => primary_address
[value] =>
)
)
)
)
)
)
)
[1] => stdClass Object
(
[link_list] => Array
(
[0] => stdClass Object
(
[name] => email_addresses
[records] => Array
(
[0] => stdClass Object
(
[link_value] => stdClass Object
(
[id] => stdClass Object
(
[name] => id
[value] => 16aeaf8b-b31f-943d-3844-4f7cb6ac63f2
)
[email_address] => stdClass Object
(
[name] => email_address
[value] => vegan.sales.im@example.cn
) | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_a_List_of_Records_With_Related_Info/index.html |
9e3bf36e16d2-5 | [value] => vegan.sales.im@example.cn
)
[opt_out] => stdClass Object
(
[name] => opt_out
[value] => 0
)
[primary_address] => stdClass Object
(
[name] => primary_address
[value] =>
)
)
)
[1] => stdClass Object
(
[link_value] => stdClass Object
(
[id] => stdClass Object
(
[name] => id
[value] => 173bacf5-5ea6-3906-d91d-4f7cb6c6e883
)
[email_address] => stdClass Object
(
[name] => email_address
[value] => kid.the.section@example.org
)
[opt_out] => stdClass Object
(
[name] => opt_out
[value] => 1
)
[primary_address] => stdClass Object
(
[name] => primary_address
[value] =>
)
)
)
)
)
)
)
)
)
Â
Last modified: 2023-02-03 21:09:36 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_a_List_of_Records_With_Related_Info/index.html |
64b20190aa46-0 | This API has been succeeded by a new version. It is recommended to upgrade to the latest API.
Retrieving a List of Records
Overview
A PHP example demonstrating how to retrieve a list of records from a module with the get_entry_list method using cURL and the v4_1 REST API.
This example will retrieve a list of leads.
Example
<?php
$url = "http://{site_url}/service/v4_1/rest.php";
$username = "admin";
$password = "password";
//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;
} | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_a_List_of_Records/index.html |
64b20190aa46-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;
//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' => 'Leads',
//The SQL WHERE clause without the word "where".
'query' => "",
//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',
'title',
),
/*
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( | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_a_List_of_Records/index.html |
64b20190aa46-2 | */
'link_name_to_fields_array' => array(
),
//The maximum number of results to return.
'max_results' => '2',
//To exclude deleted records
'deleted' => '0',
//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>';
?>
Result
stdClass Object
(
[result_count] => 2
[total_count] => 200
[next_offset] => 2
[entry_list] => Array
(
[0] => stdClass Object
(
[id] => 18124607-69d1-b158-47ff-4f7cb69344f7
[module_name] => Leads
[name_value_list] => stdClass Object
(
[id] => stdClass Object
(
[name] => id
[value] => 18124607-69d1-b158-47ff-4f7cb69344f7
)
[name] => stdClass Object
(
[name] => name
[value] => Bernie Worthey
)
[title] => stdClass Object
(
[name] => title
[value] => Senior Product Manager
)
)
)
[1] => stdClass Object
(
[id] => 1cdfddc1-2759-b007-8713-4f7cb64c2e9c
[module_name] => Leads | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_a_List_of_Records/index.html |
64b20190aa46-3 | [module_name] => Leads
[name_value_list] => stdClass Object
(
[id] => stdClass Object
(
[name] => id
[value] => 1cdfddc1-2759-b007-8713-4f7cb64c2e9c
)
[name] => stdClass Object
(
[name] => name
[value] => Bobbie Kohlmeier
)
[title] => stdClass Object
(
[name] => title
[value] => Director Operations
)
)
)
)
[relationship_list] => Array
(
)
)
Â
Last modified: 2023-02-03 21:09:36 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_a_List_of_Records/index.html |
6805f753fdfb-0 | This API has been succeeded by a new version. It is recommended to upgrade to the latest API.
Creating Notes with Attachments
Overview
A PHP example demonstrating how to create a note using set_entry and add an attachment with the set_note_attachment method using cURL and the v4_1 REST API.
Example
<?php
$url = "http://{site_url}/service/v4_1/rest.php";
$username = "admin";
$password = "password";
//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 ---------------------------------------------------- | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Creating_Notes_with_Attachments/index.html |
6805f753fdfb-1 | 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;
//create note -----------------------------------------------
$set_entry_parameters = array(
//session id
"session" => $session_id,
//The name of the module
"module_name" => "Notes",
//Record attributes
"name_value_list" => array(
//to update a record, you will nee to pass in a record id as commented below
//array("name" => "id", "value" => "9b170af9-3080-e22b-fbc1-4fea74def88f"),
array("name" => "name", "value" => "Example Note"),
),
);
$set_entry_result = call("set_entry", $set_entry_parameters, $url);
echo "<pre>";
print_r($set_entry_result);
echo "</pre>";
$note_id = $set_entry_result->id;
//create note attachment --------------------------------------
$contents = file_get_contents ("/path/to/example_file.php");
$set_note_attachment_parameters = array(
//session id | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Creating_Notes_with_Attachments/index.html |
6805f753fdfb-2 | $set_note_attachment_parameters = array(
//session id
"session" => $session_id,
//The attachment details
"note" => array(
//The ID of the note containing the attachment.
'id' => $note_id,
//The file name of the attachment.
'filename' => 'example_file.php',
//The binary contents of the file.
'file' => base64_encode($contents),
),
);
$set_note_attachment_result = call("set_note_attachment", $set_note_attachment_parameters, $url);
echo "<pre>";
print_r($set_note_attachment_result);
echo "</pre>";
?>
Result
//set_entry result
stdClass Object
(
[id] => 72508938-db19-3b5c-b7a8-50abc7ec3fdb
[entry_list] => stdClass Object
(
[name] => stdClass Object
(
[name] => name
[value] => Example Note
)
)
)
//set_note_attachment result
stdClass Object
(
[id] => 72508938-db19-3b5c-b7a8-50abc7ec3fdb
)
Last modified: 2023-02-03 21:09:36 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Creating_Notes_with_Attachments/index.html |
4507e84e786b-0 | This API has been succeeded by a new version. It is recommended to upgrade to the latest API.
Retrieving a List of Fields From a Module
Overview
A PHP example demonstrating how to retrieve fields vardefs from the accounts module with the get_module_fields method using cURL and the v4_1 REST API.
This example will only retrieve the vardefs for the 'id' and 'name' fields.
Example
<?php
$url = "http://{site_url}/service/v4_1/rest.php";
$username = "admin";
$password = "password";
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(); | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_a_List_of_Fields_From_a_Module/index.html |
4507e84e786b-1 | $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;
//retrieve fields --------------------------------
$get_module_fields_parameters = array(
//session id
'session' => $session_id,
//The name of the module from which to retrieve records
'module_name' => 'Accounts',
//Optional. Returns vardefs for the specified fields. An empty array will return all fields.
'fields' => array(
'id',
'name',
),
);
$get_module_fields_result = call("get_module_fields", $get_module_fields_parameters, $url);
echo "<pre>";
print_r($get_module_fields_result);
echo "</pre>";
?>
Result
stdClass Object
(
[module_name] => Accounts
[table_name] => accounts
[module_fields] => stdClass Object
(
[id] => stdClass Object
(
[name] => id
[type] => id
[group] =>
[id_name] =>
[label] => ID | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_a_List_of_Fields_From_a_Module/index.html |
4507e84e786b-2 | [id_name] =>
[label] => ID
[required] => 1
[options] => Array
(
)
[related_module] =>
[calculated] =>
[len] =>
)
[name] => stdClass Object
(
[name] => name
[type] => name
[group] =>
[id_name] =>
[label] => Name:
[required] => 1
[options] => Array
(
)
[related_module] =>
[calculated] =>
[len] => 150
)
)
[link_fields] => Array
(
)
)
Â
Last modified: 2023-02-03 21:09:36 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_a_List_of_Fields_From_a_Module/index.html |
67806f13096d-0 | This API has been succeeded by a new version. It is recommended to upgrade to the latest API.
Creating or Updating Teams
Overview
A PHP example demonstrating how to manipulate teams using cURL and the v4_1 REST API.
Note: If you are creating a private team for a user, you will need to set private to true and populate the associated_user_id populated. You should also populate the name and name_2 properties with the users first and last name.
Example
<?php
$url = "http://{site_url}/service/v4_1/rest.php";
$username = "admin";
$password = "password";
//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); | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Creating_or_Updating_Teams/index.html |
67806f13096d-1 | 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;
//create team -----------------------------------------------
$set_entry_parameters = array(
// session id
"session" => $session_id,
// The name of the module that the record will be create in.
"module_name" => "Teams",
// array of arrays for the record attributes
"name_value_list" => array(
/* Setting the id with a valid record id will update the record.
array(
"name" => "id",
"value" => "47dbab1d-bd78-09e8-4392-5256b4501d90"
),
*/
array(
"name" => "name",
"value" => "My Team"
),
array(
"name" => "description", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Creating_or_Updating_Teams/index.html |
67806f13096d-2 | ),
array(
"name" => "description",
"value" => "My new team"
),
//Whether the team is private.
//Private teams will have the associated_user_id populated.
array(
"name" => "private",
"value" => 0
),
),
);
$set_entry_result = call("set_entry", $set_entry_parameters, $url);
echo "<pre>";
print_r($set_entry_result);
echo "</pre>";
?>
Result
stdClass Object
(
[id] => 5c35a3be-4601-fb45-3afd-52ab78b03f89
[entry_list] => stdClass Object
(
[name] => stdClass Object
(
[name] => name
[value] => My Team
)
[description] => stdClass Object
(
[name] => description
[value] => My new team
)
[private] => stdClass Object
(
[name] => private
[value] =>
)
)
)
Last modified: 2023-02-03 21:09:36 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Creating_or_Updating_Teams/index.html |
6b5437db2cb7-0 | This API has been succeeded by a new version. It is recommended to upgrade to the latest API.
Searching Records
Overview
A PHP example demonstrating how to search the accounts module with the search_by_module method using cURL and the v4_1 REST API.
This script will return two results, sorted by the id field, and return the value of the id, name, account_type, phone_office, and assigned_user_name fields.
Example
<?php
$url = "http://{site_url}/service/v4_1/rest.php";
$username = "admin";
$password = "password";
//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); | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Searching_Records/index.html |
6b5437db2cb7-1 | $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;
//search ---------------------------------------
$search_by_module_parameters = array(
//Session id
"session" => $session_id,
//The string to search for.
'search_string' => 'Customer',
//The list of modules to query.
'modules' => array(
'Accounts',
),
//The record offset from which to start.
'offset' => 0,
//The maximum number of records to return.
'max_results' => 2,
//Filters records by the assigned user ID.
//Leave this empty if no filter should be applied.
'id' => '',
//An array of fields to return.
//If empty the default return fields will be from the active listviewdefs.
'select_fields' => array(
'id',
'name',
'account_type',
'phone_office', | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Searching_Records/index.html |
6b5437db2cb7-2 | 'name',
'account_type',
'phone_office',
'assigned_user_name',
),
//If the search is to only search modules participating in the unified search.
//Unified search is the SugarCRM Global Search alternative to Full-Text Search.
'unified_search_only' => false,
//If only records marked as favorites should be returned.
'favorites' => false
);
$search_by_module_result = call('search_by_module', $search_by_module_parameters, $url);
echo '<pre>';
print_r($search_by_module_result);
echo '</pre>';
?>
Result
stdClass Object
(
[result_count] => 2
[total_count] => 200
[next_offset] => 2
[entry_list] => Array
(
[0] => stdClass Object
(
[id] => 18124607-69d1-b158-47ff-4f7cb69344f7
[module_name] => Leads
[name_value_list] => stdClass Object
(
[id] => stdClass Object
(
[name] => id
[value] => 18124607-69d1-b158-47ff-4f7cb69344f7
)
[name] => stdClass Object
(
[name] => name
[value] => Bernie Worthey
)
[title] => stdClass Object
(
[name] => title
[value] => Senior Product Manager
)
)
)
[1] => stdClass Object
( | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Searching_Records/index.html |
6b5437db2cb7-3 | )
)
)
[1] => stdClass Object
(
[id] => 1cdfddc1-2759-b007-8713-4f7cb64c2e9c
[module_name] => Leads
[name_value_list] => stdClass Object
(
[id] => stdClass Object
(
[name] => id
[value] => 1cdfddc1-2759-b007-8713-4f7cb64c2e9c
)
[name] => stdClass Object
(
[name] => name
[value] => Bobbie Kohlmeier
)
[title] => stdClass Object
(
[name] => title
[value] => Director Operations
)
)
)
)
[relationship_list] => Array
(
)
)
Â
Last modified: 2023-02-03 21:09:36 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Searching_Records/index.html |
b2b19bbc67ee-0 | This API has been succeeded by a new version. It is recommended to upgrade to the latest API.
Retrieving Related Records
Overview
A PHP example demonstrating how to retrieve a list of related records with the get_relationships method using cURL and the v4_1 REST API.
This example will retrieve a list of leads related to a specific target list.
Example
<?php
$url = "http://{site_url}/service/v4_1/rest.php";
$username = "admin";
$password = "password";
//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; | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_Related_Records/index.html |
b2b19bbc67ee-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;
//retrieve related list ------------------------------
$get_relationships_parameters = array(
'session'=>$session_id,
//The name of the module from which to retrieve records.
'module_name' => 'ProspectLists',
//The ID of the specified module bean.
'module_id' => '76d0e694-ef66-ddd5-9bdf-4febd3af44d5',
//The relationship name of the linked field from which to return records.
'link_field_name' => 'leads',
//The portion of the WHERE clause from the SQL statement used to find the related items.
'related_module_query' => '',
//The related fields to be returned.
'related_fields' => array(
'id',
'first_name',
'last_name',
),
//For every related bean returned, specify link field names to field information.
'related_module_link_name_to_fields_array' => array(
),
//To exclude deleted records
'deleted'=> '0', | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_Related_Records/index.html |
b2b19bbc67ee-2 | ),
//To exclude deleted records
'deleted'=> '0',
//order by
'order_by' => '',
//offset
'offset' => 0,
//limit
'limit' => 5,
);
$get_relationships_result = call("get_relationships", $get_relationships_parameters, $url);
echo "<pre>";
print_r($get_relationships_result);
echo "</pre>";
?>
Results
stdClass Object
(
[entry_list] => Array
(
[0] => stdClass Object
(
[id] => 117c26c0-11d4-7b8b-cb8f-4f7cb6823dd8
[module_name] => Leads
[name_value_list] => stdClass Object
(
[id] => stdClass Object
(
[name] => id
[value] => 117c26c0-11d4-7b8b-cb8f-4f7cb6823dd8
)
[first_name] => stdClass Object
(
[name] => first_name
[value] => Diane
)
[last_name] => stdClass Object
(
[name] => last_name
[value] => Mckamey
)
)
)
[1] => stdClass Object
(
[id] => 142faeef-1a19-b53a-b780-4f7cb600c553
[module_name] => Leads
[name_value_list] => stdClass Object
(
[id] => stdClass Object
(
[name] => id | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_Related_Records/index.html |
b2b19bbc67ee-3 | [id] => stdClass Object
(
[name] => id
[value] => 142faeef-1a19-b53a-b780-4f7cb600c553
)
[first_name] => stdClass Object
(
[name] => first_name
[value] => Leonor
)
[last_name] => stdClass Object
(
[name] => last_name
[value] => Reser
)
)
)
)
[relationship_list] => Array
(
)
)
Â
Last modified: 2023-02-03 21:09:36 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_Related_Records/index.html |
1cbd9d412a9b-0 | REST API
Examples of integrating with Sugar REST APIs.
TopicsBashBash cURL examples of integrating with the REST v11 API.PHPPHP Examples interacting with the v11 REST API.
Last modified: 2023-02-03 21:04:03 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/index.html |
8c683c2b0d02-0 | PHP
PHP Examples interacting with the v11 REST API. | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/index.html |
8c683c2b0d02-1 | TopicsHow to Export a List of RecordsAn PHP example demonstrating how to export a list of records using the v11 /<module>/export/:record_list_id REST GET endpoint.How to Filter a List of RecordsA PHP example demonstrating how to filter records using the v11 /<module>/filter REST POST endpoints.How to Favorite a RecordA PHP example demonstrating how to favorite a record using the v11 <module>/:record/favorite REST PUT API endpoint.How to Manipulate File AttachmentsA PHP example demonstrating how to attach a file to a record using the v11 <module>/:record/file/:field REST POST API endpoint, then retrieve it with the GET endpoint.How to Fetch Related RecordsA PHP example demonstrating how to fetch related records using the v11 /<module>/:record/link/:link REST GET endpoints.How to Manipulate Records (CRUD)A PHP example demonstrating how to use the CRUD (Create, Read, Update, Delete) endpoints in the REST v11 API.How to Follow a RecordA PHP example demonstrating how to follow a record using the v11 /<module>/:record/subscribe REST POST endpoint.How to Unfavorite a RecordA PHP example demonstrating how to unfavorite a record using the v11 /<module>/:record/unfavorite REST PUT endpoint.How to Unfollow a RecordA PHP example demonstrating how to unfollow a record using the v11 /<module>/:record/unsubscribe REST DELETE endpoint.How to Get the Most Active UsersA PHP example demonstrating how to fetch the most active users for meetings, calls, inbound emails, and outbound emails using the v11 /mostactiveusers REST GET endpoint.How to Authenticate and Log OutA PHP example on how to authenticate and logout of the v11 REST API using the /oauth2/token and /oauth2/logout POST endpoints.How to PingA PHP example demonstrating how to ping using the REST v11 /ping GET endpoint.How to Fetch the Current Users TimeA PHP example demonstrating how to fetch the current users | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/index.html |
8c683c2b0d02-2 | GET endpoint.How to Fetch the Current Users TimeA PHP example demonstrating how to fetch the current users time with the v11 /ping/whattimeisit REST GET endpoint.How to Fetch Recently Viewed RecordsA PHP example demonstrating how to retrieve recently viewed records using the v11 /recent REST GET endpoint.How to Use the Global SearchA PHP example demonstrating how to globally search for records using the REST v11 /search GET endpoint.How to Check for Duplicate RecordsAn PHP example demonstrating how to check for duplicate records using the v11 /<module>/duplicateCheck REST POST endpoint.How to Manipulate QuotesA PHP example demonstrating how to manipulate Quotes and related record data such as ProductBundles, Products, and ProductBundleNotes.How to Manipulate Tags (CRUD)A PHP example demonstrating how to work with tags using the v11 REST endpoints. | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/index.html |
8c683c2b0d02-3 | Last modified: 2023-02-03 21:09:36 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/index.html |
8cc42f064174-0 | How to Fetch Related Records
Overview
A PHP example demonstrating how to fetch related records using the v11 /<module>/:record/link/:link REST GET endpoints.
Fetching Related Records
Authenticating
First, you will need to authenticate to the Sugar API. An example is shown below:
<?php
$instance_url = "http://{site_url}/rest/v11";
$username = "admin";
$password = "password";
//Login - POST /oauth2/token
$auth_url = $instance_url . "/oauth2/token";
$oauth2_token_arguments = array(
"grant_type" => "password",
//client id - default is sugar.
//It is recommended to create your own in Admin > OAuth Keys
"client_id" => "sugar",
"client_secret" => "",
"username" => $username,
"password" => $password,
//platform type - default is base.
//It is recommend to change the platform to a custom name such as "custom_api" to avoid authentication conflicts.
"platform" => "custom_api"
);
$auth_request = curl_init($auth_url);
curl_setopt($auth_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($auth_request, CURLOPT_HEADER, false);
curl_setopt($auth_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($auth_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($auth_request, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($auth_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json"
));
//convert arguments to json
$json_arguments = json_encode($oauth2_token_arguments);
curl_setopt($auth_request, CURLOPT_POSTFIELDS, $json_arguments);
//execute request | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html |
8cc42f064174-1 | curl_setopt($auth_request, CURLOPT_POSTFIELDS, $json_arguments);
//execute request
$oauth2_token_response = curl_exec($auth_request);
//decode oauth2 response to get token
$oauth2_token_response_obj = json_decode($oauth2_token_response);
$oauth_token = $oauth2_token_response_obj->access_token;
More information on authenticating can be found in the How to Authenticate and Log Out example and /oauth2/logout endpoint documentation.
Fetching Related Records
Next, we can fetch the related records we want to return using the /<module>/:record/link/:link endpoint with a GET request where
Element
Meaning
<module>
The parent module name
:record
The parent records ID
link
the actual word "link"
:link
The name of the relationship to fetch
In this example, we will fetch the related Contacts for an Account
//Identify records to fetch - POST /<module>/:record/link/:link
$fetch_url = $instance_url . "/Accounts/d8f05e67-dee3-553d-0040-5342e88f2fd1/link/contacts";
$fetch_request = curl_init($fetch_url);
curl_setopt($fetch_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($fetch_request, CURLOPT_HEADER, false);
curl_setopt($fetch_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($fetch_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($fetch_request, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($fetch_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"oauth-token: {$oauth_token}"
));
//execute request
$fetch_response = curl_exec($fetch_request);
//decode json
$fetch_response_obj = json_decode($fetch_response); | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html |
8cc42f064174-2 | //decode json
$fetch_response_obj = json_decode($fetch_response);
Request
http://{site_url}/rest/v11/Accounts/d8f05e67-dee3-553d-0040-5342e88f2fd1/link/contacts
Response
The data received from the server is shown below:
{
"next_offset":-1,
"records":[
{
"my_favorite":false,
"following":false,
"id":"819f4149-b007-a6da-a5fa-56fedbf2de77",
"name":"Florine Marcus",
"date_entered":"2016-04-01T15:34:00-05:00",
"date_modified":"2016-04-01T15:34:00-05:00",
"modified_user_id":"1",
"modified_by_name":"Administrator",
"created_by":"1",
"created_by_name":"Administrator",
"doc_owner":"",
"user_favorites":"",
"description":"",
"deleted":false,
"assigned_user_id":"seed_will_id",
"assigned_user_name":"Will Westin",
"team_count":"",
"team_name":[
{
"id":"East",
"name":"East",
"name_2":"",
"primary":true
},
{
"id":"West",
"name":"West",
"name_2":"",
"primary":false
}
],
"email":[
{
"email_address":"support27@example.tv",
"primary_address":true,
"reply_to_address":false,
"invalid_email":false, | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html |
8cc42f064174-3 | "reply_to_address":false,
"invalid_email":false,
"opt_out":false
},
{
"email_address":"support.support.kid@example.net",
"primary_address":false,
"reply_to_address":false,
"invalid_email":false,
"opt_out":true
}
],
"email1":"support27@example.tv",
"email2":"",
"invalid_email":false,
"email_opt_out":false,
"email_addresses_non_primary":"",
"salutation":"",
"first_name":"Florine",
"last_name":"Marcus",
"full_name":"Florine Marcus",
"title":"President",
"facebook":"",
"twitter":"",
"googleplus":"",
"department":"",
"do_not_call":false,
"phone_home":"(746) 162-2314",
"phone_mobile":"(941) 088-2874",
"phone_work":"(827) 541-9614",
"phone_other":"",
"phone_fax":"",
"primary_address_street":"1715 Scott Dr",
"primary_address_street_2":"",
"primary_address_street_3":"",
"primary_address_city":"Alabama",
"primary_address_state":"NY",
"primary_address_postalcode":"70187",
"primary_address_country":"USA",
"alt_address_street":"",
"alt_address_street_2":"",
"alt_address_street_3":"",
"alt_address_city":"",
"alt_address_state":"",
"alt_address_postalcode":"",
"alt_address_country":"", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html |
8cc42f064174-4 | "alt_address_postalcode":"",
"alt_address_country":"",
"assistant":"",
"assistant_phone":"",
"picture":"",
"email_and_name1":"",
"lead_source":"Employee",
"account_name":"MTM Investment Bank F S B",
"account_id":"e8c641ca-1b8c-74c1-d08d-56fedbdd3187",
"dnb_principal_id":"",
"opportunity_role_fields":"",
"opportunity_role_id":"",
"opportunity_role":"",
"reports_to_id":"",
"report_to_name":"",
"birthdate":"",
"portal_name":"FlorineMarcus119",
"portal_active":true,
"portal_password":true,
"portal_password1":null,
"portal_app":"",
"preferred_language":"en_us",
"campaign_id":"",
"campaign_name":"",
"c_accept_status_fields":"",
"m_accept_status_fields":"",
"accept_status_id":"",
"accept_status_name":"",
"accept_status_calls":"",
"accept_status_meetings":"",
"sync_contact":false,
"mkto_sync":false,
"mkto_id":null,
"mkto_lead_score":null,
"_acl":{
"fields":{
}
},
"_module":"Contacts"
},
{
"my_favorite":false,
"following":false,
"id":"527cc1a9-7984-91fe-4148-56fedbc356aa",
"name":"Shaneka Aceto", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html |
8cc42f064174-5 | "name":"Shaneka Aceto",
"date_entered":"2016-04-01T15:34:00-05:00",
"date_modified":"2016-04-01T15:34:00-05:00",
"modified_user_id":"1",
"modified_by_name":"Administrator",
"created_by":"1",
"created_by_name":"Administrator",
"doc_owner":"",
"user_favorites":"",
"description":"",
"deleted":false,
"assigned_user_id":"seed_will_id",
"assigned_user_name":"Will Westin",
"team_count":"",
"team_name":[
{
"id":"East",
"name":"East",
"name_2":"",
"primary":true
},
{
"id":"West",
"name":"West",
"name_2":"",
"primary":false
}
],
"email":[
{
"email_address":"support17@example.cn",
"primary_address":true,
"reply_to_address":false,
"invalid_email":false,
"opt_out":false
},
{
"email_address":"section.sugar.the@example.tv",
"primary_address":false,
"reply_to_address":false,
"invalid_email":false,
"opt_out":true
}
],
"email1":"support17@example.cn",
"email2":"",
"invalid_email":false,
"email_opt_out":false,
"email_addresses_non_primary":"",
"salutation":"",
"first_name":"Shaneka", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html |
8cc42f064174-6 | "salutation":"",
"first_name":"Shaneka",
"last_name":"Aceto",
"full_name":"Shaneka Aceto",
"title":"IT Developer",
"facebook":"",
"twitter":"",
"googleplus":"",
"department":"",
"do_not_call":false,
"phone_home":"(502) 528-5151",
"phone_mobile":"(816) 719-3739",
"phone_work":"(994) 769-5855",
"phone_other":"",
"phone_fax":"",
"primary_address_street":"123 Anywhere Street",
"primary_address_street_2":"",
"primary_address_street_3":"",
"primary_address_city":"Denver",
"primary_address_state":"NY",
"primary_address_postalcode":"15128",
"primary_address_country":"USA",
"alt_address_street":"",
"alt_address_street_2":"",
"alt_address_street_3":"",
"alt_address_city":"",
"alt_address_state":"",
"alt_address_postalcode":"",
"alt_address_country":"",
"assistant":"",
"assistant_phone":"",
"picture":"",
"email_and_name1":"",
"lead_source":"Email",
"account_name":"MTM Investment Bank F S B",
"account_id":"e8c641ca-1b8c-74c1-d08d-56fedbdd3187",
"dnb_principal_id":"",
"opportunity_role_fields":"",
"opportunity_role_id":"",
"opportunity_role":"",
"reports_to_id":"", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html |
8cc42f064174-7 | "opportunity_role":"",
"reports_to_id":"",
"report_to_name":"",
"birthdate":"",
"portal_name":"ShanekaAceto151",
"portal_active":true,
"portal_password":true,
"portal_password1":null,
"portal_app":"",
"preferred_language":"en_us",
"campaign_id":"",
"campaign_name":"",
"c_accept_status_fields":"",
"m_accept_status_fields":"",
"accept_status_id":"",
"accept_status_name":"",
"accept_status_calls":"",
"accept_status_meetings":"",
"sync_contact":false,
"mkto_sync":false,
"mkto_id":null,
"mkto_lead_score":null,
"_acl":{
"fields":{
}
},
"_module":"Contacts"
},
{
"my_favorite":false,
"following":false,
"id":"42d703ed-f834-f87c-967d-56fedb044051",
"name":"Johnnie Pina",
"date_entered":"2016-04-01T15:34:00-05:00",
"date_modified":"2016-04-01T15:34:00-05:00",
"modified_user_id":"1",
"modified_by_name":"Administrator",
"created_by":"1",
"created_by_name":"Administrator",
"doc_owner":"",
"user_favorites":"",
"description":"",
"deleted":false,
"assigned_user_id":"seed_will_id",
"assigned_user_name":"Will Westin", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html |
8cc42f064174-8 | "assigned_user_name":"Will Westin",
"team_count":"",
"team_name":[
{
"id":"East",
"name":"East",
"name_2":"",
"primary":true
},
{
"id":"West",
"name":"West",
"name_2":"",
"primary":false
}
],
"email":[
{
"email_address":"sugar.support.hr@example.co.uk",
"primary_address":true,
"reply_to_address":false,
"invalid_email":false,
"opt_out":false
},
{
"email_address":"support.im@example.tw",
"primary_address":false,
"reply_to_address":false,
"invalid_email":false,
"opt_out":true
}
],
"email1":"sugar.support.hr@example.co.uk",
"email2":"",
"invalid_email":false,
"email_opt_out":false,
"email_addresses_non_primary":"",
"salutation":"",
"first_name":"Johnnie",
"last_name":"Pina",
"full_name":"Johnnie Pina",
"title":"VP Operations",
"facebook":"",
"twitter":"",
"googleplus":"",
"department":"",
"do_not_call":false,
"phone_home":"(159) 335-1423",
"phone_mobile":"(580) 140-4050",
"phone_work":"(418) 792-9611",
"phone_other":"",
"phone_fax":"",
"primary_address_street":"345 Sugar Blvd.", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html |
8cc42f064174-9 | "phone_fax":"",
"primary_address_street":"345 Sugar Blvd.",
"primary_address_street_2":"",
"primary_address_street_3":"",
"primary_address_city":"Denver",
"primary_address_state":"NY",
"primary_address_postalcode":"70648",
"primary_address_country":"USA",
"alt_address_street":"",
"alt_address_street_2":"",
"alt_address_street_3":"",
"alt_address_city":"",
"alt_address_state":"",
"alt_address_postalcode":"",
"alt_address_country":"",
"assistant":"",
"assistant_phone":"",
"picture":"",
"email_and_name1":"",
"lead_source":"Direct Mail",
"account_name":"MTM Investment Bank F S B",
"account_id":"e8c641ca-1b8c-74c1-d08d-56fedbdd3187",
"dnb_principal_id":"",
"opportunity_role_fields":"",
"opportunity_role_id":"",
"opportunity_role":"",
"reports_to_id":"",
"report_to_name":"",
"birthdate":"",
"portal_name":"JohnniePina194",
"portal_active":true,
"portal_password":true,
"portal_password1":null,
"portal_app":"",
"preferred_language":"en_us",
"campaign_id":"",
"campaign_name":"",
"c_accept_status_fields":"",
"m_accept_status_fields":"",
"accept_status_id":"",
"accept_status_name":"",
"accept_status_calls":"",
"accept_status_meetings":"", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html |
8cc42f064174-10 | "accept_status_calls":"",
"accept_status_meetings":"",
"sync_contact":false,
"mkto_sync":false,
"mkto_id":null,
"mkto_lead_score":null,
"_acl":{
"fields":{
}
},
"_module":"Contacts"
}
]
}
Download
You can download the full API example here
Last modified: 2023-02-03 21:09:36 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html |
14a02c6efd90-0 | How to Unfavorite a Record
Overview
A PHP example demonstrating how to unfavorite a record using the v11 /<module>/:record/unfavorite REST PUTÂ endpoint.
Unfavoriting a Record
Authenticating
First, you will need to authenticate to the Sugar API. An example is shown below:
<?php
$instance_url = "http://{site_url}/rest/v11";
$username = "admin";
$password = "password";
//Login - POST /oauth2/token
$auth_url = $instance_url . "/oauth2/token";
$oauth2_token_arguments = array(
"grant_type" => "password",
//client id - default is sugar.
//It is recommended to create your own in Admin > OAuth Keys
"client_id" => "sugar",
"client_secret" => "",
"username" => $username,
"password" => $password,
//platform type - default is base.
//It is recommend to change the platform to a custom name such as "custom_api" to avoid authentication conflicts.
"platform" => "custom_api"
);
$auth_request = curl_init($auth_url);
curl_setopt($auth_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($auth_request, CURLOPT_HEADER, false);
curl_setopt($auth_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($auth_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($auth_request, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($auth_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json"
));
//convert arguments to json
$json_arguments = json_encode($oauth2_token_arguments);
curl_setopt($auth_request, CURLOPT_POSTFIELDS, $json_arguments);
//execute request | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Unfavorite_a_Record/index.html |
14a02c6efd90-1 | curl_setopt($auth_request, CURLOPT_POSTFIELDS, $json_arguments);
//execute request
$oauth2_token_response = curl_exec($auth_request);
//decode oauth2 response to get token
$oauth2_token_response_obj = json_decode($oauth2_token_response);
$oauth_token = $oauth2_token_response_obj->access_token;
More information on authenticating can be found in the How to Authenticate and Log Out example and /oauth2/logout endpoint documentation.
Unfavoriting a Record
Next, we can unfavorite a specific record using the /<module>/:record/unfavorite endpoint.
//Unfavorite record - PUT //:record/unfavorite
$unfavorite_url = $instance_url . "/Accounts/ae8b1783-404a-fcb8-1e1e-56f1cc52cd1a/unfavorite";
$unfavorite_request = curl_init($unfavorite_url);
curl_setopt($unfavorite_request, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($unfavorite_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($unfavorite_request, CURLOPT_HEADER, false);
curl_setopt($unfavorite_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($unfavorite_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($unfavorite_request, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($unfavorite_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"oauth-token: {$oauth_token}"
));
//execute request
$unfavorite_response = curl_exec($unfavorite_request);
More information on the unfavorite APIÂ can be found in the /<module>/:record/unfavorite PUTÂ documentation.
Request Payload
The data sent to the server is shown below:
This endpoint does not accept any request arguments.
Response | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Unfavorite_a_Record/index.html |
14a02c6efd90-2 | This endpoint does not accept any request arguments.
Response
The data received from the server is shown below:
{
"id": "ae8b1783-404a-fcb8-1e1e-56f1cc52cd1a",
"name": "Union Bank",
"date_entered": "2016-03-22T17:49:50-05:00",
"date_modified": "2016-03-30T17:44:20-05:00",
"modified_user_id": "1",
"modified_by_name": "Administrator",
"modified_user_link": {
"full_name": "Administrator",
"id": "1",
"_acl": {
"fields": [],
"delete": "no",
"_hash": "8e11bf9be8f04daddee9d08d44ea891e"
}
},
"created_by": "1",
"created_by_name": "Administrator",
"created_by_link": {
"full_name": "Administrator",
"id": "1",
"_acl": {
"fields": [],
"delete": "no",
"_hash": "8e11bf9be8f04daddee9d08d44ea891e"
}
},
"description": "",
"deleted": false,
"facebook": "",
"twitter": "",
"googleplus": "",
"account_type": "Customer",
"industry": "Banking",
"annual_revenue": "",
"phone_fax": "",
"billing_address_street": "67321 West Siam St.",
"billing_address_street_2": "", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Unfavorite_a_Record/index.html |
14a02c6efd90-3 | "billing_address_street_2": "",
"billing_address_street_3": "",
"billing_address_street_4": "",
"billing_address_city": "Ohio",
"billing_address_state": "CA",
"billing_address_postalcode": "25159",
"billing_address_country": "USA",
"rating": "",
"phone_office": "(065) 489-6104",
"phone_alternate": "",
"website": "www.qahr.edu",
"ownership": "",
"employees": "",
"ticker_symbol": "",
"shipping_address_street": "67321 West Siam St.",
"shipping_address_street_2": "",
"shipping_address_street_3": "",
"shipping_address_street_4": "",
"shipping_address_city": "Ohio",
"shipping_address_state": "CA",
"shipping_address_postalcode": "25159",
"shipping_address_country": "USA",
"parent_id": "",
"sic_code": "",
"duns_num": "",
"parent_name": "",
"member_of": {
"name": "",
"id": "",
"_acl": {
"fields": [],
"_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
}
},
"campaign_id": "",
"campaign_name": "",
"campaign_accounts": {
"name": "",
"id": "",
"_acl": {
"fields": [],
"_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
}
},
"following": true, | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Unfavorite_a_Record/index.html |
14a02c6efd90-4 | }
},
"following": true,
"my_favorite": false,
"tag": [],
"assigned_user_id": "seed_sarah_id",
"assigned_user_name": "Sarah Smith",
"assigned_user_link": {
"full_name": "Sarah Smith",
"id": "seed_sarah_id",
"_acl": {
"fields": [],
"_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
}
},
"team_count": "",
"team_count_link": {
"team_count": "",
"id": "West",
"_acl": {
"fields": [],
"_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
}
},
"team_name": [{
"id": "East",
"name": "East",
"name_2": "",
"primary": false
}, {
"id": 1,
"name": "Global",
"name_2": "",
"primary": false
}, {
"id": "West",
"name": "West",
"name_2": "",
"primary": true
}],
"email": [{
"email_address": "hr.support.kid@example.info",
"invalid_email": false,
"opt_out": false,
"primary_address": true,
"reply_to_address": false
}, {
"email_address": "info.support.the@example.com",
"invalid_email": false,
"opt_out": false,
"primary_address": false, | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Unfavorite_a_Record/index.html |
14a02c6efd90-5 | "opt_out": false,
"primary_address": false,
"reply_to_address": false
}],
"email1": "hr.support.kid@example.info",
"email2": "info.support.the@example.com",
"invalid_email": false,
"email_opt_out": false,
"email_addresses_non_primary": "",
"_acl": {
"fields": {}
},
"_module": "Accounts"
}
Download
You can download the full API example here.
Last modified: 2023-02-03 21:09:36 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Unfavorite_a_Record/index.html |
2792dd08c8db-0 | How to Use the Global Search
Overview
A PHP example demonstrating how to globally search for records using the REST v11 /search GET endpoint.
Authenticating
First, you will need to authenticate to the Sugar API. An example is shown below:
<?php
$instance_url = "http://{site_url}/rest/v11";
$username = "admin";
$password = "password";
//Login - POST /oauth2/token
$auth_url = $instance_url . "/oauth2/token";
$oauth2_token_arguments = array(
"grant_type" => "password",
//client id - default is sugar.
//It is recommended to create your own in Admin > OAuth Keys
"client_id" => "sugar",
"client_secret" => "",
"username" => $username,
"password" => $password,
//platform type - default is base.
//It is recommend to change the platform to a custom name such as "custom_api" to avoid authentication conflicts.
"platform" => "custom_api"
);
$auth_request = curl_init($auth_url);
curl_setopt($auth_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($auth_request, CURLOPT_HEADER, false);
curl_setopt($auth_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($auth_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($auth_request, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($auth_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json"
));
//convert arguments to json
$json_arguments = json_encode($oauth2_token_arguments);
curl_setopt($auth_request, CURLOPT_POSTFIELDS, $json_arguments);
//execute request | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Use_the_Global_Search/index.html |
2792dd08c8db-1 | curl_setopt($auth_request, CURLOPT_POSTFIELDS, $json_arguments);
//execute request
$oauth2_token_response = curl_exec($auth_request);
//decode oauth2 response to get token
$oauth2_token_response_obj = json_decode($oauth2_token_response);
$oauth_token = $oauth2_token_response_obj->access_token;
More information on authenticating can be found in the How to Authenticate and Log Out example and /oauth2/logout endpoint documentation.
Searching Records
So, we will need to identify the records we want to see using the /search endpoint. In this case, we are going to search for all records that have the email address of 'jsmith@sugar.com'. In this example, there are 3 records, an Account, a Contact and a Lead.
//Set up the search parameters - GET /search
$search_url = $instance_url . "/search";
$search_arguments = array(
"q" => 'jsmith@sugar.com',
"max_num" => 3,
"offset" => 0,
"fields" => "",
"order_by" => "",
"favorites" => false,
"my_items" => false,
);
//As this request is a GET we will add the arguments to the URL
$search_url .= "?" . http_build_query($search_arguments);
$search_request = curl_init($search_url);
curl_setopt($search_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($search_request, CURLOPT_HEADER, false);
curl_setopt($search_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($search_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($search_request, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($search_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Use_the_Global_Search/index.html |
2792dd08c8db-2 | "Content-Type: application/json",
"oauth-token: {$oauth_token}"
));
//execute request
$search_response = curl_exec($search_request);
//decode json
$search_response_obj = json_decode($search_response);
More information on the search APIÂ can be found in the /search documentation.
Request
http://{site_url}/rest/v11/search?q=jsmith%40sugar.com&max_num=3&offset=0&fields=&order_by=&favorites=0&my_items=0
Response
The data received from the server is shown below:
{
"next_offset":-1,
"records":[
{
"my_favorite":false,
"following":false,
"id":"f31b2f00-468c-3d35-1e88-56fedbd3921d",
"name":"Kaycee Gibney",
"date_entered":"2016-04-01T20:34:00+00:00",
"date_modified":"2016-04-06T15:16:24+00:00",
"modified_user_id":"1",
"modified_by_name":"Administrator",
"created_by":"1",
"created_by_name":"Administrator",
"doc_owner":"",
"user_favorites":"",
"description":"",
"deleted":false,
"assigned_user_id":"seed_jim_id",
"assigned_user_name":"Jim Brennan",
"team_count":"",
"team_name":[
{
"id":"East",
"name":"East",
"name_2":"",
"primary":true
}
],
"email":[
{
"email_address":"jsmith@sugar.com", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Use_the_Global_Search/index.html |
2792dd08c8db-3 | "email":[
{
"email_address":"jsmith@sugar.com",
"invalid_email":false,
"opt_out":false,
"primary_address":true,
"reply_to_address":false
},
{
"email_address":"sales.kid.dev@example.info",
"invalid_email":false,
"opt_out":true,
"primary_address":false,
"reply_to_address":false
}
],
"email1":"jsmith@sugar.com",
"email2":"sales.kid.dev@example.info",
"invalid_email":false,
"email_opt_out":false,
"email_addresses_non_primary":"",
"salutation":"",
"first_name":"Kaycee",
"last_name":"Gibney",
"full_name":"Kaycee Gibney",
"title":"Mgr Operations",
"facebook":"",
"twitter":"",
"googleplus":"",
"department":"",
"do_not_call":false,
"phone_home":"(599) 165-2396",
"phone_mobile":"(215) 591-9574",
"phone_work":"(771) 945-3648",
"phone_other":"",
"phone_fax":"",
"primary_address_street":"321 University Ave.",
"primary_address_street_2":"",
"primary_address_street_3":"",
"primary_address_city":"Santa Monica",
"primary_address_state":"NY",
"primary_address_postalcode":"96154",
"primary_address_country":"USA",
"alt_address_street":"",
"alt_address_street_2":"",
"alt_address_street_3":"", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Use_the_Global_Search/index.html |
2792dd08c8db-4 | "alt_address_street_2":"",
"alt_address_street_3":"",
"alt_address_city":"",
"alt_address_state":"",
"alt_address_postalcode":"",
"alt_address_country":"",
"assistant":"",
"assistant_phone":"",
"picture":"",
"email_and_name1":"",
"lead_source":"Existing Customer",
"account_name":"Tracker Com LP",
"account_id":"72ad6f00-e345-1cab-b370-56fedbd23deb",
"dnb_principal_id":"",
"opportunity_role_fields":"",
"opportunity_role_id":"",
"opportunity_role":"",
"reports_to_id":"",
"report_to_name":"",
"birthdate":"",
"portal_name":"KayceeGibney33",
"portal_active":true,
"portal_password":true,
"portal_password1":null,
"portal_app":"",
"preferred_language":"en_us",
"campaign_id":"",
"campaign_name":"",
"c_accept_status_fields":"",
"m_accept_status_fields":"",
"accept_status_id":"",
"accept_status_name":"",
"accept_status_calls":"",
"accept_status_meetings":"",
"sync_contact":false,
"mkto_sync":false,
"mkto_id":null,
"mkto_lead_score":null,
"_acl":{
"fields":{
}
},
"_module":"Contacts",
"_search":{
"score":0.70710677,
"highlighted":{
"email1":{ | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Use_the_Global_Search/index.html |
2792dd08c8db-5 | "highlighted":{
"email1":{
"text":"\u003Cstrong\u003Ejsmith@sugar.com\u003C\/strong\u003E",
"module":"Contacts",
"label":"LBL_EMAIL_ADDRESS"
}
}
}
},
{
"my_favorite":false,
"following":false,
"id":"e8c641ca-1b8c-74c1-d08d-56fedbdd3187",
"name":"MTM Investment Bank F S B",
"date_entered":"2016-04-01T20:34:00+00:00",
"date_modified":"2016-04-06T15:16:52+00:00",
"modified_user_id":"1",
"modified_by_name":"Administrator",
"created_by":"1",
"created_by_name":"Administrator",
"doc_owner":"",
"user_favorites":"",
"description":"",
"deleted":false,
"assigned_user_id":"seed_will_id",
"assigned_user_name":"Will Westin",
"team_count":"",
"team_name":[
{
"id":"East",
"name":"East",
"name_2":"",
"primary":true
},
{
"id":"West",
"name":"West",
"name_2":"",
"primary":false
}
],
"email":[
{
"email_address":"jsmith@sugar.com",
"invalid_email":false,
"opt_out":false,
"primary_address":true,
"reply_to_address":false | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Use_the_Global_Search/index.html |
2792dd08c8db-6 | "primary_address":true,
"reply_to_address":false
},
{
"email_address":"the60@example.us",
"invalid_email":false,
"opt_out":false,
"primary_address":false,
"reply_to_address":false
}
],
"email1":"jsmith@sugar.com",
"email2":"the60@example.us",
"invalid_email":false,
"email_opt_out":false,
"email_addresses_non_primary":"",
"facebook":"",
"twitter":"",
"googleplus":"",
"account_type":"Customer",
"industry":"a",
"annual_revenue":"",
"phone_fax":"",
"billing_address_street":"67321 West Siam St.",
"billing_address_street_2":"",
"billing_address_street_3":"",
"billing_address_street_4":"",
"billing_address_city":"Alabama",
"billing_address_state":"NY",
"billing_address_postalcode":"52272",
"billing_address_country":"USA",
"rating":"",
"phone_office":"(012) 704-8075",
"phone_alternate":"",
"website":"www.salesqa.it",
"ownership":"",
"employees":"",
"ticker_symbol":"",
"shipping_address_street":"67321 West Siam St.",
"shipping_address_street_2":"",
"shipping_address_street_3":"",
"shipping_address_street_4":"",
"shipping_address_city":"Alabama",
"shipping_address_state":"NY",
"shipping_address_postalcode":"52272",
"shipping_address_country":"USA", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Use_the_Global_Search/index.html |
2792dd08c8db-7 | "shipping_address_country":"USA",
"parent_id":"",
"sic_code":"",
"duns_num":"",
"parent_name":"",
"campaign_id":"",
"campaign_name":"",
"_acl":{
"fields":{
}
},
"_module":"Accounts",
"_search":{
"score":0.70710677,
"highlighted":{
"email1":{
"text":"\u003Cstrong\u003Ejsmith@sugar.com\u003C\/strong\u003E",
"module":"Accounts",
"label":"LBL_EMAIL_ADDRESS"
}
}
}
},
{
"my_favorite":false,
"following":false,
"id":"f3951f4d-2d17-7939-c5ec-56fedbb9e92f",
"name":"Talia Knupp",
"date_entered":"2016-04-01T20:34:00+00:00",
"date_modified":"2016-04-06T15:33:24+00:00",
"modified_user_id":"1",
"modified_by_name":"Administrator",
"created_by":"1",
"created_by_name":"Administrator",
"doc_owner":"",
"user_favorites":"",
"description":"",
"deleted":false,
"assigned_user_id":"seed_will_id",
"assigned_user_name":"Will Westin",
"team_count":"",
"team_name":[
{
"id":"East",
"name":"East",
"name_2":"",
"primary":true | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Use_the_Global_Search/index.html |
2792dd08c8db-8 | "name_2":"",
"primary":true
},
{
"id":"West",
"name":"West",
"name_2":"",
"primary":false
}
],
"email":[
{
"email_address":"jsmith@sugar.com",
"invalid_email":false,
"opt_out":false,
"primary_address":true,
"reply_to_address":false
},
{
"email_address":"cjsmith@sugar.com",
"invalid_email":false,
"opt_out":false,
"primary_address":false,
"reply_to_address":false
}
],
"email1":"jsmith@sugar.com",
"email2":"cjsmith@sugar.com",
"invalid_email":false,
"email_opt_out":false,
"email_addresses_non_primary":"",
"salutation":"",
"first_name":"Talia",
"last_name":"Knupp",
"full_name":"Talia Knupp",
"title":"Senior Product Manager",
"facebook":"",
"twitter":"",
"googleplus":"",
"department":"",
"do_not_call":false,
"phone_home":"(963) 741-3689",
"phone_mobile":"(600) 831-9872",
"phone_work":"(680) 991-2837",
"phone_other":"",
"phone_fax":"",
"primary_address_street":"111 Silicon Valley Road",
"primary_address_street_2":"",
"primary_address_street_3":"",
"primary_address_city":"Sunnyvale", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Use_the_Global_Search/index.html |
2792dd08c8db-9 | "primary_address_city":"Sunnyvale",
"primary_address_state":"NY",
"primary_address_postalcode":"99452",
"primary_address_country":"USA",
"alt_address_street":"",
"alt_address_street_2":"",
"alt_address_street_3":"",
"alt_address_city":"",
"alt_address_state":"",
"alt_address_postalcode":"",
"alt_address_country":"",
"assistant":"",
"assistant_phone":"",
"picture":"",
"converted":false,
"refered_by":"",
"lead_source":"Word of mouth",
"lead_source_description":"",
"status":"In Process",
"status_description":"",
"reports_to_id":"",
"report_to_name":"",
"dnb_principal_id":"",
"account_name":"First National S\/B",
"account_description":"",
"contact_id":"",
"contact_name":"",
"account_id":"",
"opportunity_id":"",
"opportunity_name":"",
"opportunity_amount":"",
"campaign_id":"",
"campaign_name":"",
"c_accept_status_fields":"",
"m_accept_status_fields":"",
"accept_status_id":"",
"accept_status_name":"",
"accept_status_calls":"",
"accept_status_meetings":"",
"webtolead_email1":[
{
"email_address":"jsmith@sugar.com",
"invalid_email":false,
"opt_out":false,
"primary_address":true,
"reply_to_address":false
},
{
"email_address":"cjsmith@sugar.com", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Use_the_Global_Search/index.html |
2792dd08c8db-10 | },
{
"email_address":"cjsmith@sugar.com",
"invalid_email":false,
"opt_out":false,
"primary_address":false,
"reply_to_address":false
}
],
"webtolead_email2":[
{
"email_address":"jsmith@sugar.com",
"invalid_email":false,
"opt_out":false,
"primary_address":true,
"reply_to_address":false
},
{
"email_address":"cjsmith@sugar.com",
"invalid_email":false,
"opt_out":false,
"primary_address":false,
"reply_to_address":false
}
],
"webtolead_email_opt_out":"",
"webtolead_invalid_email":"",
"birthdate":"",
"portal_name":"",
"portal_app":"",
"website":"",
"preferred_language":"",
"mkto_sync":false,
"mkto_id":null,
"mkto_lead_score":null,
"fruits_c":"Apples",
"_acl":{
"fields":{
}
},
"_module":"Leads",
"_search":{
"score":0.70710677,
"highlighted":{
"email1":{
"text":"\u003Cstrong\u003Ejsmith@sugar.com\u003C\/strong\u003E",
"module":"Leads",
"label":"LBL_EMAIL_ADDRESS"
}
}
}
}
]
} | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Use_the_Global_Search/index.html |
2792dd08c8db-11 | }
}
}
}
]
}
There are 3 records shown above, the _module field tells you if the record is from Accounts, Contacts or Leads. The _search field is an array that tells you where in the record it found the search string. It gives you back a highlighted string that you can use for display.
Downloads
You can download the full API example here
Last modified: 2023-02-03 21:09:36 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Use_the_Global_Search/index.html |
6f506096f703-0 | How to Manipulate Records (CRUD)
Overview
A PHP example demonstrating how to use the CRUD (Create, Read, Update, Delete) endpoints in the REST v11 API.
CRUD Operations
Authenticating
First, you will need to authenticate to the Sugar API. An example is shown below:
<?php
$instance_url = "http://{site_url}/rest/v11";
$username = "admin";
$password = "password";
//Login - POST /oauth2/token
$auth_url = $instance_url . "/oauth2/token";
$oauth2_token_arguments = array(
"grant_type" => "password",
//client id - default is sugar.
//It is recommended to create your own in Admin > OAuth Keys
"client_id" => "sugar",
"client_secret" => "",
"username" => $username,
"password" => $password,
//platform type - default is base.
//It is recommend to change the platform to a custom name such as "custom_api" to avoid authentication conflicts.
"platform" => "custom_api"
);
$auth_request = curl_init($auth_url);
curl_setopt($auth_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($auth_request, CURLOPT_HEADER, false);
curl_setopt($auth_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($auth_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($auth_request, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($auth_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json"
));
//convert arguments to json
$json_arguments = json_encode($oauth2_token_arguments);
curl_setopt($auth_request, CURLOPT_POSTFIELDS, $json_arguments);
//execute request | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html |
6f506096f703-1 | curl_setopt($auth_request, CURLOPT_POSTFIELDS, $json_arguments);
//execute request
$oauth2_token_response = curl_exec($auth_request);
//decode oauth2 response to get token
$oauth2_token_response_obj = json_decode($oauth2_token_response);
$oauth_token = $oauth2_token_response_obj->access_token;
More information on authenticating can be found in the How to Authenticate and Log Out example and /oauth2/logout endpoint documentation.
Creating a Record
Next, we need to submit the record to the Sugar instance using the /<module> endpoint. In this example we are going to create an Account record with a Name of 'Test Record' and an email of 'test@sugar.com'.
//Create Records - POST /<module>
$url = $instance_url . "/Accounts";
//Set up the Record details
$record = array(
'name' => 'Test Record',
'email' => array(
array(
'email_address' => 'test@sugar.com',
'primary_address' => true
)
),
);
$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_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"oauth-token: {$oauth_token}"
));
//convert arguments to json
$json_arguments = json_encode($record);
curl_setopt($curl_request, CURLOPT_POSTFIELDS, $json_arguments);
//execute request | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html |
6f506096f703-2 | curl_setopt($curl_request, CURLOPT_POSTFIELDS, $json_arguments);
//execute request
$curl_response = curl_exec($curl_request);
//decode json
$createdRecord = json_decode($curl_response);
//display the created record
print_r($createdRecord);
curl_close($curl_request);
More information on this API endpoint can be found in the /<module> - POSTÂ documentation.
Request Payload
The data sent to the server is shown below:
{
"name": "Test Record",
"email": [{ "email_address": "test@sugar.com", "primary_address": true }]
}
Response
The data received from the server is shown below:
{
"id": "ae78a068-7a0c-11e8-8b9e-6a0001bcacb0",
"name": "Test Record",
"date_entered": "2018-06-27T15:19:11+02:00",
"date_modified": "2018-06-27T15:19:11+02:00",
"modified_user_id": "1",
"modified_by_name": "Administrator",
"modified_user_link": {
"full_name": "Administrator",
"id": "1",
"_acl": {
"fields": {
"pwd_last_changed": { "write": "no", "create": "no" },
"last_login": { "write": "no", "create": "no" }
},
"delete": "no",
"_hash": "08b99a97c2e8d792f7a44d8882b5af6d"
}
},
"created_by": "1", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html |
6f506096f703-3 | }
},
"created_by": "1",
"created_by_name": "Administrator",
"created_by_link": {
"full_name": "Administrator",
"id": "1",
"_acl": {
"fields": {
"pwd_last_changed": { "write": "no", "create": "no" },
"last_login": { "write": "no", "create": "no" }
},
"delete": "no",
"_hash": "08b99a97c2e8d792f7a44d8882b5af6d"
}
},
"description": "",
"deleted": false,
"facebook": "",
"twitter": "",
"googleplus": "",
"account_type": "",
"industry": "",
"annual_revenue": "",
"phone_fax": "",
"billing_address_street": "",
"billing_address_street_2": "",
"billing_address_street_3": "",
"billing_address_street_4": "",
"billing_address_city": "",
"billing_address_state": "",
"billing_address_postalcode": "",
"billing_address_country": "",
"rating": "",
"phone_office": "",
"phone_alternate": "",
"website": "",
"ownership": "",
"employees": "",
"ticker_symbol": "",
"shipping_address_street": "",
"shipping_address_street_2": "",
"shipping_address_street_3": "",
"shipping_address_street_4": "",
"shipping_address_city": "",
"shipping_address_state": "",
"shipping_address_postalcode": "", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html |
6f506096f703-4 | "shipping_address_state": "",
"shipping_address_postalcode": "",
"shipping_address_country": "",
"parent_id": "",
"sic_code": "",
"duns_num": "",
"parent_name": "",
"member_of": {
"name": "",
"id": "",
"_acl": { "fields": [], "_hash": "654d337e0e912edaa00dbb0fb3dc3c17" }
},
"campaign_id": "",
"campaign_name": "",
"campaign_accounts": {
"name": "",
"id": "",
"_acl": { "fields": [], "_hash": "654d337e0e912edaa00dbb0fb3dc3c17" }
},
"following": true,
"my_favorite": false,
"tag": [],
"locked_fields": [],
"assigned_user_id": "",
"assigned_user_name": "",
"assigned_user_link": {
"full_name": "",
"id": "",
"_acl": { "fields": [], "_hash": "654d337e0e912edaa00dbb0fb3dc3c17" }
},
"team_count": "",
"team_count_link": {
"team_count": "",
"id": "1",
"_acl": { "fields": [], "_hash": "654d337e0e912edaa00dbb0fb3dc3c17" }
},
"team_name": [
{
"id": "1",
"name": "Global",
"name_2": "",
"primary": true, | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html |
6f506096f703-5 | "name_2": "",
"primary": true,
"selected": false
}
],
"email": [
{
"email_address": "test@sugar.com",
"invalid_email": false,
"opt_out": false,
"email_address_id": "85125194-7a0a-11e8-9c17-6a0001bcacb0",
"primary_address": true,
"reply_to_address": false
}
],
"email1": "test@sugar.com",
"email2": "",
"invalid_email": false,
"email_opt_out": false,
"email_addresses_non_primary": "",
"test_c": "",
"dri_workflow_template_id": "",
"dri_workflow_template_name": "",
"dri_workflow_template_link": {
"name": "",
"id": "",
"_acl": { "fields": [], "_hash": "654d337e0e912edaa00dbb0fb3dc3c17" }
},
"_acl": { "fields": {} },
"_module": "Accounts"
}
Getting a Record
Next, we can get the created record from the Sugar instance using the /<module>/:record endpoint. In this example, we are going to get an Account record by it's ID, but only request the Name, Email, and Industry fields.
$id = $createdRecord->id;
//Get Record - GET //:record
$url = $instance_url . "/Accounts/$id";
//Setup request to only return some fields on module
$data = array(
'fields' => 'name,email1,industry' | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html |
6f506096f703-6 | $data = array(
'fields' => 'name,email1,industry'
);
//Add data to the URL
$url = $url."?".http_build_query($data);
$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_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"oauth-token: {$oauth_token}"
));
//execute request
$curl_response = curl_exec($curl_request);
//decode json
$record = json_decode($curl_response);
//display the created record
print_r($record);
curl_close($curl_request);
Updating a Record
Next, we can update  the record in the Sugar instance using the /<module>/:record endpoint, and the PUT Http method. In this example, we are going to update the Account record and change it's name to "Updated Test Record".
$id = $record->id;
//Update Record - PUT /<module>/:record
$url = $instance_url . "/Accounts/$id";
//Set up the Record details
$record->name = 'Updated Test Record';
$curl_request = curl_init($url);
curl_setopt($curl_request, CURLOPT_CUSTOMREQUEST, "PUT");
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); | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html |
6f506096f703-7 | 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_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"oauth-token: {$oauth_token}"
));
//convert arguments to json
$json_arguments = json_encode($record);
curl_setopt($curl_request, CURLOPT_POSTFIELDS, $json_arguments);
//execute request
$curl_response = curl_exec($curl_request);
//decode json
$updatedRecord = json_decode($curl_response);
//display the created record
echo "Updated Record Name:".$updatedRecord->name;
curl_close($curl_request);
More information on this API endpoint can be found in the /<module>/:record - PUTÂ documentation.
Request Payload
The URLÂ sent to the server is shown below:
{"name":"Updated Test Record"}
Response
The data received from the server is shown below:
{
"id": "ae78a068-7a0c-11e8-8b9e-6a0001bcacb0",
"name": "Updated Test Record",
"date_entered": "2018-06-27T15:19:11+02:00",
"date_modified": "2018-06-27T15:23:19+02:00",
"modified_user_id": "1",
"modified_by_name": "Administrator",
"modified_user_link": {
"full_name": "Administrator",
"id": "1",
"_acl": {
"fields": {
"pwd_last_changed": { "write": "no", "create": "no" }, | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html |
6f506096f703-8 | "last_login": { "write": "no", "create": "no" }
},
"delete": "no",
"_hash": "08b99a97c2e8d792f7a44d8882b5af6d"
}
},
"created_by": "1",
"created_by_name": "Administrator",
"created_by_link": {
"full_name": "Administrator",
"id": "1",
"_acl": {
"fields": {
"pwd_last_changed": { "write": "no", "create": "no" },
"last_login": { "write": "no", "create": "no" }
},
"delete": "no",
"_hash": "08b99a97c2e8d792f7a44d8882b5af6d"
}
},
"description": "",
"deleted": false,
"facebook": "",
"twitter": "",
"googleplus": "",
"account_type": "",
"industry": "",
"annual_revenue": "",
"phone_fax": "",
"billing_address_street": "",
"billing_address_street_2": "",
"billing_address_street_3": "",
"billing_address_street_4": "",
"billing_address_city": "",
"billing_address_state": "",
"billing_address_postalcode": "",
"billing_address_country": "",
"rating": "",
"phone_office": "",
"phone_alternate": "",
"website": "",
"ownership": "",
"employees": "",
"ticker_symbol": "",
"shipping_address_street": "", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html |
6f506096f703-9 | "ticker_symbol": "",
"shipping_address_street": "",
"shipping_address_street_2": "",
"shipping_address_street_3": "",
"shipping_address_street_4": "",
"shipping_address_city": "",
"shipping_address_state": "",
"shipping_address_postalcode": "",
"shipping_address_country": "",
"parent_id": "",
"sic_code": "",
"duns_num": "",
"parent_name": "",
"member_of": {
"name": "",
"id": "",
"_acl": { "fields": [], "_hash": "654d337e0e912edaa00dbb0fb3dc3c17" }
},
"campaign_id": "",
"campaign_name": "",
"campaign_accounts": {
"name": "",
"id": "",
"_acl": { "fields": [], "_hash": "654d337e0e912edaa00dbb0fb3dc3c17" }
},
"following": true,
"my_favorite": false,
"tag": [],
"locked_fields": [],
"assigned_user_id": "",
"assigned_user_name": "",
"assigned_user_link": {
"full_name": "",
"id": "",
"_acl": { "fields": [], "_hash": "654d337e0e912edaa00dbb0fb3dc3c17" }
},
"team_count": "",
"team_count_link": {
"team_count": "",
"id": "1", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html |
6f506096f703-10 | "team_count": "",
"id": "1",
"_acl": { "fields": [], "_hash": "654d337e0e912edaa00dbb0fb3dc3c17" }
},
"team_name": [
{
"id": "1",
"name": "Global",
"name_2": "",
"primary": true,
"selected": false
}
],
"email": [
{
"email_address": "test@sugar.com",
"invalid_email": false,
"opt_out": false,
"email_address_id": "85125194-7a0a-11e8-9c17-6a0001bcacb0",
"primary_address": true,
"reply_to_address": false
}
],
"email1": "test@sugar.com",
"email2": "",
"invalid_email": false,
"email_opt_out": false,
"email_addresses_non_primary": "",
"test_c": "",
"dri_workflow_template_id": "",
"dri_workflow_template_name": "",
"dri_workflow_template_link": {
"name": "",
"id": "",
"_acl": { "fields": [], "_hash": "654d337e0e912edaa00dbb0fb3dc3c17" }
},
"_acl": { "fields": {} },
"_module": "Accounts"
}
Deleting a Record
Next, we can delete the record from the Sugar instance using the /<module>/:record endpoint, by using the DELETE Http Method. | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html |
6f506096f703-11 | $id = $updatedRecord->id;
//Delete Record - DELETE /<module>/:record
$url = $instance_url . "/Accounts/$id";
$curl_request = curl_init($url);
curl_setopt($curl_request, CURLOPT_CUSTOMREQUEST, "DELETE");
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_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"oauth-token: {$oauth_token}"
));
//execute request
$curl_response = curl_exec($curl_request);
//decode json
$deletedRecord = json_decode($curl_response);
//display the created record
echo "Deleted Record:".$deletedRecord->id;
curl_close($curl_request);
More information on this API endpoint can be found in the /<module>/:record - DELETEÂ documentation.
Request Payload
The URLÂ sent to the server is shown below:
No payload is sent for this request.
Response
The data received from the server is shown below:
{"id":"ae78a068-7a0c-11e8-8b9e-6a0001bcacb0"}
Download
You can download the full API example here.Â
Last modified: 2023-02-03 21:09:36 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html |
37567405c6cd-0 | How to Favorite a Record
Overview
A PHP example demonstrating how to favorite a record using the v11 <module>/:record/favorite REST PUT API endpoint.
Favoriting a Record
Authenticating
First, you will need to authenticate to the Sugar API. An example is shown below:
<?php
$instance_url = "http://{site_url}/rest/v11";
$username = "admin";
$password = "password";
//Login - POST /oauth2/token
$auth_url = $instance_url . "/oauth2/token";
$oauth2_token_arguments = array(
"grant_type" => "password",
//client id - default is sugar.
//It is recommended to create your own in Admin > OAuth Keys
"client_id" => "sugar",
"client_secret" => "",
"username" => $username,
"password" => $password,
//platform type - default is base.
//It is recommend to change the platform to a custom name such as "custom_api" to avoid authentication conflicts.
"platform" => "custom_api"
);
$auth_request = curl_init($auth_url);
curl_setopt($auth_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($auth_request, CURLOPT_HEADER, false);
curl_setopt($auth_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($auth_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($auth_request, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($auth_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json"
));
//convert arguments to json
$json_arguments = json_encode($oauth2_token_arguments);
curl_setopt($auth_request, CURLOPT_POSTFIELDS, $json_arguments);
//execute request | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Favorite_a_Record/index.html |
37567405c6cd-1 | curl_setopt($auth_request, CURLOPT_POSTFIELDS, $json_arguments);
//execute request
$oauth2_token_response = curl_exec($auth_request);
//decode oauth2 response to get token
$oauth2_token_response_obj = json_decode($oauth2_token_response);
$oauth_token = $oauth2_token_response_obj->access_token;
More information on authenticating can be found in the How to Authenticate and Log Out example and /oauth2/logout endpoint documentation.
Favoriting a Record
Next, we can favorite a specific record using the /<module>/:record/favorite endpoint.
//Favorite record - PUT //:record/favorite
$favorite_url = $instance_url . "/Accounts/ae8b1783-404a-fcb8-1e1e-56f1cc52cd1a/favorite";
$favorite_request = curl_init($favorite_url);
curl_setopt($favorite_request, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($favorite_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($favorite_request, CURLOPT_HEADER, false);
curl_setopt($favorite_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($favorite_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($favorite_request, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($favorite_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"oauth-token: {$oauth_token}"
));
//execute request
$favorite_response = curl_exec($favorite_request);
More information on theunfavorite APIÂ can be found in the /<module>/:record/favorite PUTÂ documentation.
Request Payload
The data sent to the server is shown below:
This endpoint does not accept any request arguments.
Response
The data received from the server is shown below:
{ | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Favorite_a_Record/index.html |
37567405c6cd-2 | Response
The data received from the server is shown below:
{
"id": "ae8b1783-404a-fcb8-1e1e-56f1cc52cd1a",
"name": "Union Bank",
"date_entered": "2016-03-22T17:49:50-05:00",
"date_modified": "2016-03-30T17:44:20-05:00",
"modified_user_id": "1",
"modified_by_name": "Administrator",
"modified_user_link": {
"full_name": "Administrator",
"id": "1",
"_acl": {
"fields": [],
"delete": "no",
"_hash": "8e11bf9be8f04daddee9d08d44ea891e"
}
},
"created_by": "1",
"created_by_name": "Administrator",
"created_by_link": {
"full_name": "Administrator",
"id": "1",
"_acl": {
"fields": [],
"delete": "no",
"_hash": "8e11bf9be8f04daddee9d08d44ea891e"
}
},
"description": "",
"deleted": false,
"facebook": "",
"twitter": "",
"googleplus": "",
"account_type": "Customer",
"industry": "Banking",
"annual_revenue": "",
"phone_fax": "",
"billing_address_street": "67321 West Siam St.",
"billing_address_street_2": "",
"billing_address_street_3": "", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Favorite_a_Record/index.html |
37567405c6cd-3 | "billing_address_street_2": "",
"billing_address_street_3": "",
"billing_address_street_4": "",
"billing_address_city": "Ohio",
"billing_address_state": "CA",
"billing_address_postalcode": "25159",
"billing_address_country": "USA",
"rating": "",
"phone_office": "(065) 489-6104",
"phone_alternate": "",
"website": "www.qahr.edu",
"ownership": "",
"employees": "",
"ticker_symbol": "",
"shipping_address_street": "67321 West Siam St.",
"shipping_address_street_2": "",
"shipping_address_street_3": "",
"shipping_address_street_4": "",
"shipping_address_city": "Ohio",
"shipping_address_state": "CA",
"shipping_address_postalcode": "25159",
"shipping_address_country": "USA",
"parent_id": "",
"sic_code": "",
"duns_num": "",
"parent_name": "",
"member_of": {
"name": "",
"id": "",
"_acl": {
"fields": [],
"_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
}
},
"campaign_id": "",
"campaign_name": "",
"campaign_accounts": {
"name": "",
"id": "",
"_acl": {
"fields": [],
"_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
}
},
"following": true, | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Favorite_a_Record/index.html |
37567405c6cd-4 | }
},
"following": true,
"my_favorite": true,
"tag": [],
"assigned_user_id": "seed_sarah_id",
"assigned_user_name": "Sarah Smith",
"assigned_user_link": {
"full_name": "Sarah Smith",
"id": "seed_sarah_id",
"_acl": {
"fields": [],
"_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
}
},
"team_count": "",
"team_count_link": {
"team_count": "",
"id": "West",
"_acl": {
"fields": [],
"_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
}
},
"team_name": [{
"id": "East",
"name": "East",
"name_2": "",
"primary": false
}, {
"id": 1,
"name": "Global",
"name_2": "",
"primary": false
}, {
"id": "West",
"name": "West",
"name_2": "",
"primary": true
}],
"email": [{
"email_address": "hr.support.kid@example.info",
"invalid_email": false,
"opt_out": false,
"primary_address": true,
"reply_to_address": false
}, {
"email_address": "info.support.the@example.com",
"invalid_email": false,
"opt_out": false,
"primary_address": false, | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Favorite_a_Record/index.html |
37567405c6cd-5 | "opt_out": false,
"primary_address": false,
"reply_to_address": false
}],
"email1": "hr.support.kid@example.info",
"email2": "info.support.the@example.com",
"invalid_email": false,
"email_opt_out": false,
"email_addresses_non_primary": "",
"_acl": {
"fields": {}
},
"_module": "Accounts"
}
Download
You can download the full API example here.
Last modified: 2023-02-03 21:09:36 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Favorite_a_Record/index.html |
c96812c094f3-0 | How to Follow a Record
Overview
A PHP example demonstrating how to follow a record using the v11 /<module>/:record/subscribe REST POST endpoint.
Following a Record
Authenticating
First, you will need to authenticate to the Sugar API. An example is shown below:
<?php
$instance_url = "http://{site_url}/rest/v11";
$username = "admin";
$password = "password";
//Login - POST /oauth2/token
$auth_url = $instance_url . "/oauth2/token";
$oauth2_token_arguments = array(
"grant_type" => "password",
//client id - default is sugar.
//It is recommended to create your own in Admin > OAuth Keys
"client_id" => "sugar",
"client_secret" => "",
"username" => $username,
"password" => $password,
//platform type - default is base.
//It is recommend to change the platform to a custom name such as "custom_api" to avoid authentication conflicts.
"platform" => "custom_api"
);
$auth_request = curl_init($auth_url);
curl_setopt($auth_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($auth_request, CURLOPT_HEADER, false);
curl_setopt($auth_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($auth_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($auth_request, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($auth_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json"
));
//convert arguments to json
$json_arguments = json_encode($oauth2_token_arguments);
curl_setopt($auth_request, CURLOPT_POSTFIELDS, $json_arguments);
//execute request | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Follow_a_Record/index.html |
c96812c094f3-1 | curl_setopt($auth_request, CURLOPT_POSTFIELDS, $json_arguments);
//execute request
$oauth2_token_response = curl_exec($auth_request);
//decode oauth2 response to get token
$oauth2_token_response_obj = json_decode($oauth2_token_response);
$oauth_token = $oauth2_token_response_obj->access_token;
More information on authenticating can be found in the How to Authenticate and Log Out example and /oauth2/logout endpoint documentation.
Following a Record
Next, we can follow a specific record using the /<module>/:record/subscribe endpoint.
//Subscribe to record - POST //:record/subscribe
$subscribe_url = $instance_url . "/Accounts/ae8b1783-404a-fcb8-1e1e-56f1cc52cd1a/subscribe";
$subscribe_request = curl_init($subscribe_url);
curl_setopt($subscribe_request, CURLOPT_POST, 1);
curl_setopt($subscribe_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($subscribe_request, CURLOPT_HEADER, false);
curl_setopt($subscribe_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($subscribe_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($subscribe_request, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($subscribe_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"oauth-token: {$oauth_token}"
));
//execute request
$subscribe_response = curl_exec($subscribe_request);
More information on the subscribe APIÂ can be found in the /<module>/:record/subscribe POSTÂ documentation.
Request Payload
The data sent to the server is shown below:
This endpoint does not accept any request arguments.
Response
The data received from the server is shown below: | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Follow_a_Record/index.html |
c96812c094f3-2 | Response
The data received from the server is shown below:
"58f96315-9e75-6562-42e9-5705917d2cdc"
Download
You can download the full API example here.
Last modified: 2023-02-03 21:09:36 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Follow_a_Record/index.html |
cdbc86e7b62e-0 | How to Filter a List of Records
Overview
A PHP example demonstrating how to filter records using the v11 /<module>/filter REST POST endpoints.
Filtering Records
Authenticating
First, you will need to authenticate to the Sugar API. An example is shown below:
<?php
$instance_url = "http://{site_url}/rest/v11";
$username = "admin";
$password = "password";
//Login - POST /oauth2/token
$auth_url = $instance_url . "/oauth2/token";
$oauth2_token_arguments = array(
"grant_type" => "password",
//client id - default is sugar.
//It is recommended to create your own in Admin > OAuth Keys
"client_id" => "sugar",
"client_secret" => "",
"username" => $username,
"password" => $password,
//platform type - default is base.
//It is recommend to change the platform to a custom name such as "custom_api" to avoid authentication conflicts.
"platform" => "custom_api"
);
$auth_request = curl_init($auth_url);
curl_setopt($auth_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($auth_request, CURLOPT_HEADER, false);
curl_setopt($auth_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($auth_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($auth_request, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($auth_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json"
));
//convert arguments to json
$json_arguments = json_encode($oauth2_token_arguments);
curl_setopt($auth_request, CURLOPT_POSTFIELDS, $json_arguments);
//execute request | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Filter_a_List_of_Records/index.html |
cdbc86e7b62e-1 | curl_setopt($auth_request, CURLOPT_POSTFIELDS, $json_arguments);
//execute request
$oauth2_token_response = curl_exec($auth_request);
//decode oauth2 response to get token
$oauth2_token_response_obj = json_decode($oauth2_token_response);
$oauth_token = $oauth2_token_response_obj->access_token;
More information on authenticating can be found in the How to Authenticate and Log Out example and /oauth2/logout endpoint documentation.
Filtering Records
Next, we can filter the records we want to return using the /<module>/filter endpoint with a POST request.
//Identify records to export - POST /<module>/filter
$filter_url = $instance_url . "/Accounts/filter";
$filter_arguments = array(
"filter" => array(
array(
'$or' => array(
array(
//name starts with 'a'
"name" => array(
'$starts'=>"A",
)
),
array(
//name starts with 'b'
"name" => array(
'$starts'=>"b",
)
)
),
),
),
"max_num" => 2,
"offset" => 0,
"fields" => "id",
"order_by" => "date_entered",
"favorites" => false,
"my_items" => false,
);
$filter_request = curl_init($filter_url);
curl_setopt($filter_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($filter_request, CURLOPT_HEADER, false);
curl_setopt($filter_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($filter_request, CURLOPT_RETURNTRANSFER, 1); | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Filter_a_List_of_Records/index.html |
cdbc86e7b62e-2 | curl_setopt($filter_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($filter_request, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($filter_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"oauth-token: {$oauth_token}"
));
//convert arguments to json
$json_arguments = json_encode($filter_arguments);
curl_setopt($filter_request, CURLOPT_POSTFIELDS, $json_arguments);
//execute request
$filter_response = curl_exec($filter_request);
//decode json
$filter_response_obj = json_decode($filter_response);
More information on the filter APIÂ can be found in the /<module>/filter documentation.
Note : The /<module>/filter endpoint can be called using a GET request as well, though long URL requests can have issues so the POST request is recommended.Â
Request Payload
The data sent to the server is shown below:
{
"filter":[
{
"$or":[
{
"name":{
"$starts":"A"
}
},
{
"name":{
"$starts":"b"
}
}
]
}
],
"max_num":2,
"offset":0,
"fields":"id",
"order_by":"date_entered",
"favorites":false,
"my_items":false
}
Response
The data received from the server is shown below:
{
"next_offset":2,
"records":[
{
"id":"f16760a4-3a52-f77d-1522-5703ca28925f", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Filter_a_List_of_Records/index.html |
cdbc86e7b62e-3 | "date_modified":"2016-04-05T10:23:28-04:00",
"_acl":{
"fields":{
}
},
"_module":"Accounts"
},
{
"id":"ec409fbb-2b22-4f32-7fa1-5703caf78dc3",
"date_modified":"2016-04-05T10:23:28-04:00",
"_acl":{
"fields":{
}
},
"_module":"Accounts"
}
]
}
Download
You can download the full API example using POST here and using GET here.
Last modified: 2023-02-03 21:09:36 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Filter_a_List_of_Records/index.html |
46418eb08c53-0 | How to Ping
Overview
A PHP example demonstrating how to ping using the REST v11 /ping GET endpoint.
Pinging
Authenticating
First, you will need to authenticate to the Sugar API. An example is shown below:
<?php
$instance_url = "http://{site_url}/rest/v11";
$username = "admin";
$password = "password";
//Login - POST /oauth2/token
$auth_url = $instance_url . "/oauth2/token";
$oauth2_token_arguments = array(
"grant_type" => "password",
//client id - default is sugar.
//It is recommended to create your own in Admin > OAuth Keys
"client_id" => "sugar",
"client_secret" => "",
"username" => $username,
"password" => $password,
//platform type - default is base.
//It is recommend to change the platform to a custom name such as "custom_api" to avoid authentication conflicts.
"platform" => "custom_api"
);
$auth_request = curl_init($auth_url);
curl_setopt($auth_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($auth_request, CURLOPT_HEADER, false);
curl_setopt($auth_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($auth_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($auth_request, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($auth_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json"
));
//convert arguments to json
$json_arguments = json_encode($oauth2_token_arguments);
curl_setopt($auth_request, CURLOPT_POSTFIELDS, $json_arguments);
//execute request
$oauth2_token_response = curl_exec($auth_request); | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Ping/index.html |
46418eb08c53-1 | //execute request
$oauth2_token_response = curl_exec($auth_request);
//decode oauth2 response to get token
$oauth2_token_response_obj = json_decode($oauth2_token_response);
$oauth_token = $oauth2_token_response_obj->access_token;
More information on authenticating can be found in the How to Authenticate and Log Out example and /oauth2/logout endpoint documentation.
Pinging
Once we have authenticated, we can now ping the system as shown below.
//Ping - GET /ping
$ping_url = $instance_url . "/ping";
$ping_request = curl_init($ping_url);
curl_setopt($ping_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($ping_request, CURLOPT_HEADER, false); //needed to return file headers
curl_setopt($ping_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ping_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ping_request, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ping_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"oauth-token: {$oauth_token}"
));
$ping_response = curl_exec($ping_request);
More information on pinging can be found in the /ping documentation.
Response
"pong"
Download
You can download the full API example here.
Last modified: 2023-02-03 21:09:36 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Ping/index.html |
d392f943d990-0 | How to Fetch Recently Viewed Records
Overview
A PHP example demonstrating how to retrieve recently viewed records using the v11 /recent REST GET endpoint.
Authenticating
First, you will need to authenticate to the Sugar API. An example is shown below:
<?php
$instance_url = "http://{site_url}/rest/v11";
$username = "admin";
$password = "password";
//Login - POST /oauth2/token
$auth_url = $instance_url . "/oauth2/token";
$oauth2_token_arguments = array(
"grant_type" => "password",
//client id - default is sugar.
//It is recommended to create your own in Admin > OAuth Keys
"client_id" => "sugar",
"client_secret" => "",
"username" => $username,
"password" => $password,
//platform type - default is base.
//It is recommend to change the platform to a custom name such as "custom_api" to avoid authentication conflicts.
"platform" => "custom_api"
);
$auth_request = curl_init($auth_url);
curl_setopt($auth_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($auth_request, CURLOPT_HEADER, false);
curl_setopt($auth_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($auth_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($auth_request, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($auth_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json"
));
//convert arguments to json
$json_arguments = json_encode($oauth2_token_arguments);
curl_setopt($auth_request, CURLOPT_POSTFIELDS, $json_arguments);
//execute request | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Recently_Viewed_Records/index.html |
d392f943d990-1 | curl_setopt($auth_request, CURLOPT_POSTFIELDS, $json_arguments);
//execute request
$oauth2_token_response = curl_exec($auth_request);
//decode oauth2 response to get token
$oauth2_token_response_obj = json_decode($oauth2_token_response);
$oauth_token = $oauth2_token_response_obj->access_token;
More information on authenticating can be found in the How to Authenticate and Log Out example and /oauth2/logout endpoint documentation.Â
Recently Viewed Records
Next, we will need to identify the records we want to see using the /recent endpoint. In this case, we are going to request Accounts, Contacts and Leads.
//Set up the search parameters - GET /recent
$recent_url = $instance_url . "/recent";
$recent_arguments = array(
"module_list" => 'Accounts,Contacts,Leads',
);
//As this request is a GET we will add the arguments to the URL
$recent_url .= "?" . http_build_query($recent_arguments);
$recent_request = curl_init($recent_url);
curl_setopt($recent_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($recent_request, CURLOPT_HEADER, false);
curl_setopt($recent_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($recent_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($recent_request, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($recent_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"oauth-token: {$oauth_token}"
));
//execute request
$recent_response = curl_exec($recent_request);
//decode json
$recent_response_obj = json_decode($recent_response);
More information on the search APIÂ can be found in the /recent documentation.
Request | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Recently_Viewed_Records/index.html |
d392f943d990-2 | More information on the search APIÂ can be found in the /recent documentation.
Request
http://{site_url}/rest/v11/recent?module_list=Accounts%2CContacts%2CLeads
Response
The data received from the server is shown below:
{
"next_offset":-1,
"records":[
{
"my_favorite":false,
"following":false,
"id":"f3951f4d-2d17-7939-c5ec-56fedbb9e92f",
"name":"Talia Knupp",
"date_entered":"2016-04-01T15:34:00-05:00",
"date_modified":"2016-04-06T10:33:24-05:00",
"modified_user_id":"1",
"modified_by_name":"Administrator",
"created_by":"1",
"created_by_name":"Administrator",
"doc_owner":"",
"user_favorites":"",
"description":"",
"deleted":false,
"assigned_user_id":"seed_will_id",
"assigned_user_name":"Will Westin",
"team_count":"",
"team_name":[
{
"id":"East",
"name":"East",
"name_2":"",
"primary":true
},
{
"id":"West",
"name":"West",
"name_2":"",
"primary":false
}
],
"email":[
{
"email_address":"jsmith@sugar.com",
"invalid_email":false,
"opt_out":false,
"primary_address":true,
"reply_to_address":false | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Recently_Viewed_Records/index.html |
d392f943d990-3 | "primary_address":true,
"reply_to_address":false
},
{
"email_address":"cjsmith@sugar.com",
"invalid_email":false,
"opt_out":false,
"primary_address":false,
"reply_to_address":false
}
],
"email1":"jsmith@sugar.com",
"email2":"cjsmith@sugar.com",
"invalid_email":false,
"email_opt_out":false,
"email_addresses_non_primary":"",
"salutation":"",
"first_name":"Talia",
"last_name":"Knupp",
"full_name":"Talia Knupp",
"title":"Senior Product Manager",
"facebook":"",
"twitter":"",
"googleplus":"",
"department":"",
"do_not_call":false,
"phone_home":"(963) 741-3689",
"phone_mobile":"(600) 831-9872",
"phone_work":"(680) 991-2837",
"phone_other":"",
"phone_fax":"",
"primary_address_street":"111 Silicon Valley Road",
"primary_address_street_2":"",
"primary_address_street_3":"",
"primary_address_city":"Sunnyvale",
"primary_address_state":"NY",
"primary_address_postalcode":"99452",
"primary_address_country":"USA",
"alt_address_street":"",
"alt_address_street_2":"",
"alt_address_street_3":"",
"alt_address_city":"",
"alt_address_state":"",
"alt_address_postalcode":"",
"alt_address_country":"", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Recently_Viewed_Records/index.html |
d392f943d990-4 | "alt_address_postalcode":"",
"alt_address_country":"",
"assistant":"",
"assistant_phone":"",
"picture":"",
"converted":false,
"refered_by":"",
"lead_source":"Word of mouth",
"lead_source_description":"",
"status":"In Process",
"status_description":"",
"reports_to_id":"",
"report_to_name":"",
"dnb_principal_id":"",
"account_name":"First National S\/B",
"account_description":"",
"contact_id":"",
"contact_name":"",
"account_id":"",
"opportunity_id":"",
"opportunity_name":"",
"opportunity_amount":"",
"campaign_id":"",
"campaign_name":"",
"c_accept_status_fields":"",
"m_accept_status_fields":"",
"accept_status_id":"",
"accept_status_name":"",
"accept_status_calls":"",
"accept_status_meetings":"",
"webtolead_email1":[
{
"email_address":"jsmith@sugar.com",
"invalid_email":false,
"opt_out":false,
"primary_address":true,
"reply_to_address":false
},
{
"email_address":"cjsmith@sugar.com",
"invalid_email":false,
"opt_out":false,
"primary_address":false,
"reply_to_address":false
}
],
"webtolead_email2":[
{
"email_address":"jsmith@sugar.com",
"invalid_email":false,
"opt_out":false, | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Recently_Viewed_Records/index.html |
d392f943d990-5 | "invalid_email":false,
"opt_out":false,
"primary_address":true,
"reply_to_address":false
},
{
"email_address":"cjsmith@sugar.com",
"invalid_email":false,
"opt_out":false,
"primary_address":false,
"reply_to_address":false
}
],
"webtolead_email_opt_out":"",
"webtolead_invalid_email":"",
"birthdate":"",
"portal_name":"",
"portal_app":"",
"website":"",
"preferred_language":"",
"mkto_sync":false,
"mkto_id":null,
"mkto_lead_score":null,
"fruits_c":"Apples",
"_acl":{
"fields":{
}
},
"_module":"Leads",
"_last_viewed_date":"2016-04-06T10:33:24-05:00"
},
{
"my_favorite":false,
"following":false,
"id":"e8c641ca-1b8c-74c1-d08d-56fedbdd3187",
"name":"MTM Investment Bank F S B",
"date_entered":"2016-04-01T15:34:00-05:00",
"date_modified":"2016-04-06T10:16:52-05:00",
"modified_user_id":"1",
"modified_by_name":"Administrator",
"created_by":"1",
"created_by_name":"Administrator",
"doc_owner":"",
"user_favorites":"",
"description":"", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Recently_Viewed_Records/index.html |
d392f943d990-6 | "user_favorites":"",
"description":"",
"deleted":false,
"assigned_user_id":"seed_will_id",
"assigned_user_name":"Will Westin",
"team_count":"",
"team_name":[
{
"id":"East",
"name":"East",
"name_2":"",
"primary":true
},
{
"id":"West",
"name":"West",
"name_2":"",
"primary":false
}
],
"email":[
{
"email_address":"jsmith@sugar.com",
"invalid_email":false,
"opt_out":false,
"primary_address":true,
"reply_to_address":false
},
{
"email_address":"the60@example.us",
"invalid_email":false,
"opt_out":false,
"primary_address":false,
"reply_to_address":false
}
],
"email1":"jsmith@sugar.com",
"email2":"the60@example.us",
"invalid_email":false,
"email_opt_out":false,
"email_addresses_non_primary":"",
"facebook":"",
"twitter":"",
"googleplus":"",
"account_type":"Customer",
"industry":"a",
"annual_revenue":"",
"phone_fax":"",
"billing_address_street":"67321 West Siam St.",
"billing_address_street_2":"",
"billing_address_street_3":"",
"billing_address_street_4":"",
"billing_address_city":"Alabama",
"billing_address_state":"NY", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Recently_Viewed_Records/index.html |
d392f943d990-7 | "billing_address_city":"Alabama",
"billing_address_state":"NY",
"billing_address_postalcode":"52272",
"billing_address_country":"USA",
"rating":"",
"phone_office":"(012) 704-8075",
"phone_alternate":"",
"website":"www.salesqa.it",
"ownership":"",
"employees":"",
"ticker_symbol":"",
"shipping_address_street":"67321 West Siam St.",
"shipping_address_street_2":"",
"shipping_address_street_3":"",
"shipping_address_street_4":"",
"shipping_address_city":"Alabama",
"shipping_address_state":"NY",
"shipping_address_postalcode":"52272",
"shipping_address_country":"USA",
"parent_id":"",
"sic_code":"",
"duns_num":"",
"parent_name":"",
"campaign_id":"",
"campaign_name":"",
"_acl":{
"fields":{
}
},
"_module":"Accounts",
"_last_viewed_date":"2016-04-06T10:16:52-05:00"
},
{
"my_favorite":false,
"following":false,
"id":"f31b2f00-468c-3d35-1e88-56fedbd3921d",
"name":"Kaycee Gibney",
"date_entered":"2016-04-01T15:34:00-05:00",
"date_modified":"2016-04-06T10:16:24-05:00",
"modified_user_id":"1",
"modified_by_name":"Administrator", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Recently_Viewed_Records/index.html |
d392f943d990-8 | "modified_user_id":"1",
"modified_by_name":"Administrator",
"created_by":"1",
"created_by_name":"Administrator",
"doc_owner":"",
"user_favorites":"",
"description":"",
"deleted":false,
"assigned_user_id":"seed_jim_id",
"assigned_user_name":"Jim Brennan",
"team_count":"",
"team_name":[
{
"id":"East",
"name":"East",
"name_2":"",
"primary":true
}
],
"email":[
{
"email_address":"jsmith@sugar.com",
"invalid_email":false,
"opt_out":false,
"primary_address":true,
"reply_to_address":false
},
{
"email_address":"sales.kid.dev@example.info",
"invalid_email":false,
"opt_out":true,
"primary_address":false,
"reply_to_address":false
}
],
"email1":"jsmith@sugar.com",
"email2":"sales.kid.dev@example.info",
"invalid_email":false,
"email_opt_out":false,
"email_addresses_non_primary":"",
"salutation":"",
"first_name":"Kaycee",
"last_name":"Gibney",
"full_name":"Kaycee Gibney",
"title":"Mgr Operations",
"facebook":"",
"twitter":"",
"googleplus":"",
"department":"",
"do_not_call":false,
"phone_home":"(599) 165-2396", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Recently_Viewed_Records/index.html |
d392f943d990-9 | "phone_home":"(599) 165-2396",
"phone_mobile":"(215) 591-9574",
"phone_work":"(771) 945-3648",
"phone_other":"",
"phone_fax":"",
"primary_address_street":"321 University Ave.",
"primary_address_street_2":"",
"primary_address_street_3":"",
"primary_address_city":"Santa Monica",
"primary_address_state":"NY",
"primary_address_postalcode":"96154",
"primary_address_country":"USA",
"alt_address_street":"",
"alt_address_street_2":"",
"alt_address_street_3":"",
"alt_address_city":"",
"alt_address_state":"",
"alt_address_postalcode":"",
"alt_address_country":"",
"assistant":"",
"assistant_phone":"",
"picture":"",
"email_and_name1":"",
"lead_source":"Existing Customer",
"account_name":"Tracker Com LP",
"account_id":"72ad6f00-e345-1cab-b370-56fedbd23deb",
"dnb_principal_id":"",
"opportunity_role_fields":"",
"opportunity_role_id":"",
"opportunity_role":"",
"reports_to_id":"",
"report_to_name":"",
"birthdate":"",
"portal_name":"KayceeGibney33",
"portal_active":true,
"portal_password":true,
"portal_password1":null,
"portal_app":"",
"preferred_language":"en_us",
"campaign_id":"",
"campaign_name":"",
"c_accept_status_fields":"", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Recently_Viewed_Records/index.html |
d392f943d990-10 | "campaign_name":"",
"c_accept_status_fields":"",
"m_accept_status_fields":"",
"accept_status_id":"",
"accept_status_name":"",
"accept_status_calls":"",
"accept_status_meetings":"",
"sync_contact":false,
"mkto_sync":false,
"mkto_id":null,
"mkto_lead_score":null,
"_acl":{
"fields":{
}
},
"_module":"Contacts",
"_last_viewed_date":"2016-04-06T10:16:24-05:00"
}
]
}
There are 3 records shown above, the _module field tells you if the record is from Accounts, Contacts or Leads. The _last_viewed_date will tell you when the record was last seen.
Downloads
You can download the full API example here
Last modified: 2023-02-03 21:09:36 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Recently_Viewed_Records/index.html |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.