id
stringlengths
14
16
text
stringlengths
33
5.27k
source
stringlengths
105
270
7bb710a1c7c3-6
"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", "created_by_name": "Administrator", "created_by_link": { "full_name": "Administrator", "id": "1", "_acl": { "fields": {
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-7
"id": "1", "_acl": { "fields": { "pwd_last_changed": { "write": "no", "create": "no" }, "last_login": { "write": "no", "create": "no" } }, "delete": "no", "_hash": "08b99a97c2e8d792f7a44d8882b5af6d" } }, "description": "", "deleted": false, "name_lower": "tag name", "following": "", "my_favorite": false, "locked_fields": [], "source_id": "", "source_type": "", "source_meta": "",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-8
"source_type": "", "source_meta": "", "assigned_user_id": "1", "assigned_user_name": "Administrator", "assigned_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" } }, "_acl": { "fields": {} }, "_module": "Tags" }
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-9
"_module": "Tags" } Creating Records with Tags You can also create tags when creating new records. All you need to do populate the tag field as an array when creating a record. Here is an example that demonstrates using the /<module> POST endpoint. //Create Records with Tags - / POST $url = $instance_url . "/Accounts"; //Set up the Record details with Tags $record = array( 'name' => 'Test Record', 'tag' => array( 'First Tag', 'Second Tag' ) ); $curl_request = curl_init($url); curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-10
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);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-11
//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", "tag": [ "First Tag", "Second Tag" ] } Response The data sent to the server is shown below: { "id": "ea507760-0ffd-11e8-bcf5-6a0001bcacb0", "name": "Test Record",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-12
"name": "Test Record", "date_entered": "2018-02-12T15:06:25+01:00", "date_modified": "2018-02-12T15:06:25+01: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",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-13
}, "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" }
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-14
} }, "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": "",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-15
"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": "", "shipping_address_country": "", "parent_id": "", "sic_code": "", "duns_num": "",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-16
"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": [ {
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-17
"my_favorite": false, "tag": [ { "id": "ea69c120-0ffd-11e8-b5f6-6a0001bcacb0", "name": "First Tag", "tags__name_lower": "first tag" }, { "id": "eafb28e0-0ffd-11e8-8d80-6a0001bcacb0", "name": "Second Tag", "tags__name_lower": "second tag" } ], "locked_fields": [], "assigned_user_id": "", "assigned_user_name": "", "assigned_user_link": { "full_name": "", "id": "",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-18
"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, "selected": false } ], "email": [],
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-19
"selected": false } ], "email": [], "email1": "", "email2": "", "invalid_email": "", "email_opt_out": "", "email_addresses_non_primary": "", "calculated_c": "", "_acl": { "fields": {} }, "_module": "Accounts" } Reading/Retrieving Tags Next, we can retrieve the records using the /Tags/:record GET endpoint. An example for retrieving the tag records is shown below.  //Reading/Retrieving Tags - /Tags GET $url = $instance_url . "/Tags/12c6ee48-1000-11e8-8838-6a0001bcacb0";
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-20
$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}" ));
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-21
"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 $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>/:record GET documentation.  Request Payload No payload is sent for this request. Response {
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-22
Request Payload No payload is sent for this request. Response { "id": "12c6ee48-1000-11e8-8838-6a0001bcacb0", "name": "Tag Name", "date_entered": "2018-02-12T15:21:52+01:00", "date_modified": "2018-02-12T15:21:52+01: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_Tags_CRUD/index.html
7bb710a1c7c3-23
"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",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-24
}, "delete": "no", "_hash": "08b99a97c2e8d792f7a44d8882b5af6d" } }, "description": "", "deleted": false, "name_lower": "tag name", "following": "", "my_favorite": false, "locked_fields": [], "source_id": "", "source_type": "", "source_meta": "", "assigned_user_id": "1", "assigned_user_name": "Administrator", "assigned_user_link": { "full_name": "Administrator", "id": "1", "_acl": { "fields": {
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-25
"id": "1", "_acl": { "fields": { "pwd_last_changed": { "write": "no", "create": "no" }, "last_login": { "write": "no", "create": "no" } }, "delete": "no", "_hash": "08b99a97c2e8d792f7a44d8882b5af6d" } }, "_acl": { "fields": {} }, "_module": "Tags" } Updating Tags You can update a tag using the /Tags/:record PUT endpoint. In this example, we are going to update the Tag record that we created in Creating Tags section and change its name to "Renamed Tag Name".
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-26
//Update Tags - /Tags PUT $url = $instance_url . "/Tags/12c6ee48-1000-11e8-8838-6a0001bcacb0"; //Set up the new tag name $record = array( 'name' => 'Renamed Tag Name', ); $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_Tags_CRUD/index.html
7bb710a1c7c3-27
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
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-28
//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 {"name": "Renamed Tag Name"} Response { "id": "12c6ee48-1000-11e8-8838-6a0001bcacb0", "name": "Renamed Tag Name", "date_entered": "2018-02-12T15:21:52+01:00", "date_modified": "2018-02-12T16:07:18+01:00", "modified_user_id": "1", "modified_by_name": "Administrator", "modified_user_link": {
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-29
"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", "created_by_name": "Administrator", "created_by_link": { "full_name": "Administrator", "id": "1", "_acl": { "fields": {
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-30
"id": "1", "_acl": { "fields": { "pwd_last_changed": { "write": "no", "create": "no" }, "last_login": { "write": "no", "create": "no" } }, "delete": "no", "_hash": "08b99a97c2e8d792f7a44d8882b5af6d" } }, "description": "", "deleted": false, "name_lower": "renamed tag name", "following": "", "my_favorite": false, "locked_fields": [], "source_id": "", "source_type": "", "source_meta": "",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-31
"source_type": "", "source_meta": "", "assigned_user_id": "1", "assigned_user_name": "Administrator", "assigned_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" } }, "_acl": { "fields": {} }, "_module": "Tags" }
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-32
"_module": "Tags" } Deleting Tags Finally, we can delete the record we created using the /Tags/:record DELETE API request. //Delete Tags - /Tags DELETE $url = $instance_url . "/Tags/12c6ee48-1000-11e8-8838-6a0001bcacb0"; $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);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-33
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);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-34
curl_close($curl_request); More information on this API endpoint can be found in the /<module>/:record DELETE documentation.  Request Payload No payload is sent for this request. Response {"id":"12c6ee48-1000-11e8-8838-6a0001bcacb0"} 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_Tags_CRUD/index.html
be04a5caf613-0
How to Export a List of Records Overview An PHP example demonstrating how to export a list of records using the v11 /<module>/export/:record_list_id REST GET endpoint. Exporting 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
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Export_a_List_of_Records/index.html
be04a5caf613-1
//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);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Export_a_List_of_Records/index.html
be04a5caf613-2
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); //decode oauth2 response to get token $oauth2_token_response_obj = json_decode($oauth2_token_response);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Export_a_List_of_Records/index.html
be04a5caf613-3
$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 will need to identify the records we want to export using the /<module>/filter endpoint. //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'
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Export_a_List_of_Records/index.html
be04a5caf613-4
) ), 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);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Export_a_List_of_Records/index.html
be04a5caf613-5
curl_setopt($filter_request, CURLOPT_SSL_VERIFYPEER, 0); 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
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Export_a_List_of_Records/index.html
be04a5caf613-6
$filter_response = curl_exec($filter_request); //decode json $filter_response_obj = json_decode($filter_response); //store ids of records to export $export_ids = array(); foreach ($filter_response_obj->records as $record) { $export_ids[] = $record->id; } More information on the filter API can be found in the /<module>/filter documentation. Request Payload The data sent to the server is shown below: { "filter":[ { "$or":[ { "name":{ "$starts":"A" } }, { "name":{ "$starts":"b" } } ] }
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Export_a_List_of_Records/index.html
be04a5caf613-7
"$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", "date_modified":"2016-04-05T10:23:28-04:00", "_acl":{ "fields":{ } }, "_module":"Accounts" }, {
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Export_a_List_of_Records/index.html
be04a5caf613-8
}, "_module":"Accounts" }, { "id":"ec409fbb-2b22-4f32-7fa1-5703caf78dc3", "date_modified":"2016-04-05T10:23:28-04:00", "_acl":{ "fields":{ } }, "_module":"Accounts" } ] } Creating a Record List Once we have the list of ids, we then need to create a record list in Sugar that consists of those ids. //Create a record list - POST /<module>/record_list $record_list_url = $instance_url . "/Accounts/record_list"; $record_list_arguments = array( "records" => $export_ids,
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Export_a_List_of_Records/index.html
be04a5caf613-9
"records" => $export_ids, ); $record_list_request = curl_init($record_list_url); curl_setopt($record_list_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($record_list_request, CURLOPT_HEADER, false); curl_setopt($record_list_request, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($record_list_request, CURLOPT_RETURNTRANSFER, 1); curl_setopt($record_list_request, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($record_list_request, CURLOPT_HTTPHEADER, array(
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Export_a_List_of_Records/index.html
be04a5caf613-10
"Content-Type: application/json", "oauth-token: {$oauth_token}" )); //convert arguments to json $json_arguments = json_encode($record_list_arguments); curl_setopt($record_list_request, CURLOPT_POSTFIELDS, $json_arguments); //execute request $record_list_response = curl_exec($record_list_request); Request Payload The data sent to the server is shown below: { "records":[ "f16760a4-3a52-f77d-1522-5703ca28925f", "ec409fbb-2b22-4f32-7fa1-5703caf78dc3" ] } Response
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Export_a_List_of_Records/index.html
be04a5caf613-11
] } Response The data received from the server is shown below: { "id":"ef963176-4845-bc55-b03e-570430b4173c", "assigned_user_id":"1", "module_name":"Accounts", "records":[ "f16760a4-3a52-f77d-1522-5703ca28925f", "ec409fbb-2b22-4f32-7fa1-5703caf78dc3" ], "date_modified":"2016-04-05 21:39:19" } Exporting Records Once we have the record list created, we can then export the CSV file. //Export Records - GET /<module>/export/:record_list_id
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Export_a_List_of_Records/index.html
be04a5caf613-12
//Export Records - GET /<module>/export/:record_list_id $export_url = $instance_url . "/Accounts/export/" . $record_list_response_obj->id; $export_request = curl_init($export_url); curl_setopt($export_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($export_request, CURLOPT_HEADER, true); //needed to return file headers curl_setopt($export_request, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($export_request, CURLOPT_RETURNTRANSFER, 1); curl_setopt($export_request, CURLOPT_FOLLOWLOCATION, 0);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Export_a_List_of_Records/index.html
be04a5caf613-13
curl_setopt($export_request, CURLOPT_HTTPHEADER, array( "Content-Type: application/json", "oauth-token: {$oauth_token}" )); $export_response = curl_exec($export_request); //set headers from response list($headers, $content) = explode("\r\n\r\n", $export_response ,2); foreach (explode("\r\n",$headers) as $header) { header($header); } $content = trim($content); echo $content; More information on exporting records can be found in the /<module>/export/:record_list_id documentation. Response The data received from the server is shown below: HTTP/1.1 200 OK
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Export_a_List_of_Records/index.html
be04a5caf613-14
The data received from the server is shown below: HTTP/1.1 200 OK Date: Tue, 05 Apr 2016 21:50:32 GMT Server: Apache/2.2.29 (Unix) DAV/2 PHP/5.3.29 mod_ssl/2.2.29 OpenSSL/0.9.8zg X-Powered-By: PHP/5.3.29 Expires: Cache-Control: max-age=10, private Pragma: Content-Disposition: attachment; filename=Accounts.csv Content-transfer-encoding: binary Last-Modified: Tue, 05 Apr 2016 21:50:32 GMT ETag: 9b34f5d74e0298aaf7fd1f27d02e14f2
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Export_a_List_of_Records/index.html
be04a5caf613-15
Content-Length: 1703 Connection: close Content-Type: application/octet-stream; charset=ISO-8859-1 "Name","ID","Website","Office Phone","Alternate Phone","Fax","Billing Street","Billing City","Billing State","Billing Postal Code","Billing Country","Shipping Street","Shipping City","Shipping State","Shipping Postal Code","Shipping Country","Description","Type","Industry","Annual Revenue","Employees","SIC Code","Ticker Symbol","Parent Account ID","Ownership","Campaign ID","Rating","Assigned User Name","Assigned User ID","Team ID","Teams","Team Set ID","Date Created","Date Modified","Modified By Name","Modified By ID","Created By","Created By ID","Deleted","test","Facebook Account","Twitter Account","Google Plus ID","DUNS","Email","Invalid Email","Email Opt Out","Non-primary emails"
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Export_a_List_of_Records/index.html
be04a5caf613-16
"Arts & Crafts Inc","ec409fbb-2b22-4f32-7fa1-5703caf78dc3","www.hrinfo.tw","(252) 456-8602","","","777 West Filmore Ln","Los Angeles","CA","77076","USA","777 West Filmore Ln","Los Angeles","CA","77076","USA","","Customer","Hospitality","","","","","","","","","Max Jensen","seed_max_id","West","West, East, Global","dec43cb2-5273-8be2-968a-5703cadee75f","2016-04-05 10:23","2016-04-05
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Export_a_List_of_Records/index.html
be04a5caf613-17
10:23","2016-04-05 10:23","Administrator","1","Administrator","1","0","","","","","","[email protected]","0","0","[email protected],0,0"
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Export_a_List_of_Records/index.html
be04a5caf613-18
"B.H. Edwards Inc","f16760a4-3a52-f77d-1522-5703ca28925f","www.sectiondev.edu","(361) 765-0216","","","111 Silicon Valley Road","Persistance","CA","29709","USA","111 Silicon Valley Road","Persistance","CA","29709","USA","","Customer","Apparel","","","","","","","","","Sally Bronsen","seed_sally_id","West","West","West","2016-04-05 10:23","2016-04-05 10:23","Administrator","1","Administrator","1","0","","","","","","[email protected]","0","1","[email protected],0,0" Download You can download the full API example here.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Export_a_List_of_Records/index.html
be04a5caf613-19
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_Export_a_List_of_Records/index.html
80bd052ffc79-0
How to Unfollow a Record Overview A PHP example demonstrating how to unfollow a record using the v11 /<module>/:record/unsubscribe REST DELETE endpoint. Unfollowing 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
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Unfollow_a_Record/index.html
80bd052ffc79-1
//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);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Unfollow_a_Record/index.html
80bd052ffc79-2
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); //decode oauth2 response to get token $oauth2_token_response_obj = json_decode($oauth2_token_response);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Unfollow_a_Record/index.html
80bd052ffc79-3
$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. Unfollowing a Record Next, we can unfollow a specific record using the /<module>/:record/unsubscribe endpoint. //Unfollow a record - DELETE /<module>/:record/unsubscribe $unsubscribe_url = $instance_url . "/Accounts/ae8b1783-404a-fcb8-1e1e-56f1cc52cd1a/unsubscribe"; $unsubscribe_request = curl_init($unsubscribe_url);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Unfollow_a_Record/index.html
80bd052ffc79-4
$unsubscribe_request = curl_init($unsubscribe_url); curl_setopt($unsubscribe_request, CURLOPT_CUSTOMREQUEST, "DELETE"); curl_setopt($unsubscribe_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($unsubscribe_request, CURLOPT_HEADER, false); curl_setopt($unsubscribe_request, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($unsubscribe_request, CURLOPT_RETURNTRANSFER, 1); curl_setopt($unsubscribe_request, CURLOPT_FOLLOWLOCATION, 0);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Unfollow_a_Record/index.html
80bd052ffc79-5
curl_setopt($unsubscribe_request, CURLOPT_HTTPHEADER, array( "Content-Type: application/json", "oauth-token: {$oauth_token}" )); //execute request $unsubscribe_response = curl_exec($unsubscribe_request); More information on the unsubscribe API can be found in the /<module>/:record/unsubscribe DELETE 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: true 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_Unfollow_a_Record/index.html
1d91152c83da-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" => "",
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
1d91152c83da-1
"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);
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
1d91152c83da-2
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); //decode oauth2 response to get token $oauth2_token_response_obj = json_decode($oauth2_token_response); $oauth_token = $oauth2_token_response_obj->access_token;
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
1d91152c83da-3
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 '[email protected]'.  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" => '[email protected]', "max_num" => 3, "offset" => 0, "fields" => "", "order_by" => "", "favorites" => 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
1d91152c83da-4
"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);
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
1d91152c83da-5
curl_setopt($search_request, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($search_request, CURLOPT_HTTPHEADER, array( "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
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
1d91152c83da-6
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":"",
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
1d91152c83da-7
"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":"[email protected]", "invalid_email":false, "opt_out":false, "primary_address":true, "reply_to_address":false }, { "email_address":"[email protected]",
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
1d91152c83da-8
"email_address":"[email protected]", "invalid_email":false, "opt_out":true, "primary_address":false, "reply_to_address":false } ], "email1":"[email protected]", "email2":"[email protected]", "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":"",
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
1d91152c83da-9
"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":"",
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
1d91152c83da-10
"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":"",
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
1d91152c83da-11
"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":"",
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
1d91152c83da-12
"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":{ "text":"\u003Cstrong\[email protected]\u003C\/strong\u003E", "module":"Contacts", "label":"LBL_EMAIL_ADDRESS" } } } }, { "my_favorite":false, "following":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
1d91152c83da-13
{ "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,
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
1d91152c83da-14
"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":"[email protected]", "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
1d91152c83da-15
"reply_to_address":false }, { "email_address":"[email protected]", "invalid_email":false, "opt_out":false, "primary_address":false, "reply_to_address":false } ], "email1":"[email protected]", "email2":"[email protected]", "invalid_email":false, "email_opt_out":false, "email_addresses_non_primary":"", "facebook":"", "twitter":"", "googleplus":"", "account_type":"Customer", "industry":"a", "annual_revenue":"", "phone_fax":"",
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
1d91152c83da-16
"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":"",
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
1d91152c83da-17
"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",
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
1d91152c83da-18
"fields":{ } }, "_module":"Accounts", "_search":{ "score":0.70710677, "highlighted":{ "email1":{ "text":"\u003Cstrong\[email protected]\u003C\/strong\u003E", "module":"Accounts", "label":"LBL_EMAIL_ADDRESS" } } } }, { "my_favorite":false, "following":false, "id":"f3951f4d-2d17-7939-c5ec-56fedbb9e92f", "name":"Talia Knupp",
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
1d91152c83da-19
"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",
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
1d91152c83da-20
{ "id":"East", "name":"East", "name_2":"", "primary":true }, { "id":"West", "name":"West", "name_2":"", "primary":false } ], "email":[ { "email_address":"[email protected]", "invalid_email":false, "opt_out":false, "primary_address":true, "reply_to_address":false }, { "email_address":"[email protected]", "invalid_email":false, "opt_out":false, "primary_address":false, "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
1d91152c83da-21
"reply_to_address":false } ], "email1":"[email protected]", "email2":"[email protected]", "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",
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
1d91152c83da-22
"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":"",
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
1d91152c83da-23
"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":"",
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
1d91152c83da-24
"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":"[email protected]", "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
1d91152c83da-25
"reply_to_address":false }, { "email_address":"[email protected]", "invalid_email":false, "opt_out":false, "primary_address":false, "reply_to_address":false } ], "webtolead_email2":[ { "email_address":"[email protected]", "invalid_email":false, "opt_out":false, "primary_address":true, "reply_to_address":false }, { "email_address":"[email protected]", "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_Use_the_Global_Search/index.html
1d91152c83da-26
"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":{
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
1d91152c83da-27
"score":0.70710677, "highlighted":{ "email1":{ "text":"\u003Cstrong\[email protected]\u003C\/strong\u003E", "module":"Leads", "label":"LBL_EMAIL_ADDRESS" } } } } ] } 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
7d81a5878144-0
How to Authenticate and Log Out Overview A PHP example on how to authenticate and logout of the v11 REST API using the /oauth2/token and /oauth2/logout POST endpoints. Authenticating
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Authenticate_and_Log_Out/index.html
7d81a5878144-1
Authenticating The example below demonstrates how to authenticate to the REST v11 API. It is important to note that the oauth2 token arguments takes in several parameters that you should be aware of. The platform argument tends to cause confusion in that it is used to authenticate a user to a specific platform. Since Sugar only allows 1 user in the system at a time per platform, authenticating an integration script with a platform type of "base" will logout any current users in the system using those credentials. To work around this, your custom scripts should have a new platform type specified such as "custom_api" or any other static text you prefer. The client_id and client_secret parameters can be used for additional security based on client types. You can create your own client type in Admin > OAuth Keys. More information can be found in the /oauth2/token documentation. An example script is shown below:
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Authenticate_and_Log_Out/index.html
7d81a5878144-2
<?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.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Authenticate_and_Log_Out/index.html
7d81a5878144-3
"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
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Authenticate_and_Log_Out/index.html
7d81a5878144-4
"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); Request Payload The data sent to the server is shown below: { "grant_type":"password", "client_id":"sugar", "client_secret":"", "username":"admin", "password":"password", "platform":"custom_api" } 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_Authenticate_and_Log_Out/index.html
7d81a5878144-5
} Response The data received from the server is shown below: { "access_token":"c6d495c9-bb25-81d2-5f81-533ef6479f9b", "expires_in":3600, "token_type":"bearer", "scope":null, "refresh_token":"cbc40e67-12bc-4b56-a1d9-533ef62f2601", "refresh_expires_in":1209600, "download_token":"cc5d1a9f-6627-3349-96e5-533ef6b1a493" } Logout
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Authenticate_and_Log_Out/index.html
7d81a5878144-6
} Logout To log out of a session, a request can be made to the  /oauth2/logout POST endpoint. More information can be found in the /oauth2/logout documentation. An example extending off of the above authentication example is shown below: //Logout - POST /oauth2/logout $logout_url = $instance_url . "/oauth2/logout"; //decode oauth2 repsonse to get token $oauth2_token_response_obj = json_decode($oauth2_token_response); $oauth_token = $oauth2_token_response_obj->access_token; $logout_request = curl_init($logout_url);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Authenticate_and_Log_Out/index.html
7d81a5878144-7
$logout_request = curl_init($logout_url); curl_setopt($logout_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($logout_request, CURLOPT_HEADER, false); curl_setopt($logout_request, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($logout_request, CURLOPT_RETURNTRANSFER, 1); curl_setopt($logout_request, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($logout_request, CURLOPT_HTTPHEADER, array( "Content-Type: application/json", "oauth-token: {$oauth_token}" ));
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Authenticate_and_Log_Out/index.html
7d81a5878144-8
"oauth-token: {$oauth_token}" )); //set empty post fields curl_setopt($logout_request, CURLOPT_POSTFIELDS, array()); //execute request $oauth2_logout_response = curl_exec($logout_request); Response The data received from the server is shown below: { "success":true } 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_Authenticate_and_Log_Out/index.html
e4c2a35f86d2-0
Adding Field Validation to the Record View Overview This page explains how to add additional field validation to the record view. In the following examples, we will extend and override the stock Accounts record view to add custom validation. The custom validation will require the Office Phone field when the account type is set to "Customer" and also require the user to enter at least one email address. Error Messages When throwing a validation error, Sugar has several stock messages you may choose to use. They are shown below: Error Key Label Description maxValue ERROR_MAXVALUE This maximum value of this field minValue ERROR_MINVALUE This minimum value of this field maxLength ERROR_MAX_FIELD_LENGTH The max length of this field minLength ERROR_MIN_FIELD_LENGTH The min length of this field datetime ERROR_DATETIME This field requires a valid date required
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_Field_Validation_to_the_Record_View/index.html
e4c2a35f86d2-1
datetime ERROR_DATETIME This field requires a valid date required ERROR_FIELD_REQUIRED This field is required email ERROR_EMAIL There is an invalid email address primaryEmail ERROR_PRIMARY_EMAIL No primary email address is set duplicateEmail ERROR_DUPLICATE_EMAIL There is a duplicate email address number ERROR_NUMBER This field requires a valid number isBefore ERROR_IS_BEFORE The date of this field can not be after another date isAfter ERROR_IS_AFTER The date of this field can not be before another date You also have the option of displaying multiple error messages at a time. The example below would throw an error message notifying the user that the selected field is required and that it is also not a number.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_Field_Validation_to_the_Record_View/index.html
e4c2a35f86d2-2
errors['<field name>'] = errors['<field name>'] || {}; errors['<field name>'].required = true; errors['<field name>'].number = true; Custom Error Messages Custom error message can be used by appending custom language keys to app.error.errorName2Keys when initializing an extended controller. To accomplish this, create a new language key in the $app_strings. An example of this is shown below: ./custom/Extension/application/Ext/Language/en_us.error_custom_message.php <?php $app_strings['ERROR_CUSTOM_MESSAGE'] = 'My custom error message.';
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_Field_Validation_to_the_Record_View/index.html
e4c2a35f86d2-3
Next, you will need to update your controller to use the new language key. To accomplish this, add your custom language key to the app.error.errorName2Keys array in the initialize method: initialize: function (options) { this._super('initialize', [options]); //add custom message key app.error.errorName2Keys['custom_message'] = 'ERROR_CUSTOM_MESSAGE'; .... }, Once completed, you can call your custom message by setting the app.error.errorName2Keys entry to true as shown below: errors['phone_office'] = errors['phone_office'] || {}; errors['phone_office'].custom_message = true; Method 1: Extending the RecordView and CreateView Controllers
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_Field_Validation_to_the_Record_View/index.html
e4c2a35f86d2-4
Method 1: Extending the RecordView and CreateView Controllers One way to validate fields on record view is by creating record and create view controllers. This method requires a duplication of code due to the hierarchy design, however, it does organize the code by module and extend the core functionality. To accomplish this, override and extend the create view controller. This handles the validation when a user is creating a new record. Once the controller has been properly extended, define the validation check and use the model.addValidationTask method to append your function to the save validation. ./custom/modules/Accounts/clients/base/views/create/create.js ({ extendsFrom: 'CreateView', initialize: function (options) { this._super('initialize', [options]); //add validation tasks
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_Field_Validation_to_the_Record_View/index.html
e4c2a35f86d2-5
this._super('initialize', [options]); //add validation tasks this.model.addValidationTask('check_account_type', _.bind(this._doValidateCheckType, this)); this.model.addValidationTask('check_email', _.bind(this._doValidateEmail, this)); }, _doValidateCheckType: function(fields, errors, callback) { //validate type requirements if (this.model.get('account_type') == 'Customer' && _.isEmpty(this.model.get('phone_office'))) { errors['phone_office'] = errors['phone_office'] || {}; errors['phone_office'].required = true; } callback(null, fields, errors); },
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_Field_Validation_to_the_Record_View/index.html
e4c2a35f86d2-6
} callback(null, fields, errors); }, _doValidateEmail: function(fields, errors, callback) { //validate email requirements if (_.isEmpty(this.model.get('email'))) { errors['email'] = errors['email'] || {}; errors['email'].required = true; } callback(null, fields, errors); }, }) Next, duplicate the validation logic for the record view. This handles the validation when editing existing records. ./custom/modules/Accounts/clients/base/views/record/record.js ({ /* because 'accounts' already has a record view, we need to extend it */ extendsFrom: 'AccountsRecordView', initialize: function (options) { this._super('initialize', [options]);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_Field_Validation_to_the_Record_View/index.html
e4c2a35f86d2-7
this._super('initialize', [options]); //add validation tasks this.model.addValidationTask('check_account_type', _.bind(this._doValidateCheckType, this)); this.model.addValidationTask('check_email', _.bind(this._doValidateEmail, this)); }, _doValidateCheckType: function(fields, errors, callback) { //validate requirements if (this.model.get('account_type') == 'Customer' && _.isEmpty(this.model.get('phone_office'))) { errors['phone_office'] = errors['phone_office'] || {}; errors['phone_office'].required = true; } callback(null, fields, errors); },
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_Field_Validation_to_the_Record_View/index.html