id
stringlengths 14
16
| text
stringlengths 33
5.27k
| source
stringlengths 105
270
|
---|---|---|
bd0f1f84f106-1 | ),
),
);
Copied File Example
This example copies a file to  ./custom/src/MyLibrary/MyCustomClass.php, which adds the custom namespaced class Sugarcrm\Sugarcrm\custom\MyLibrary\MyCustomClass to the application.
<?php
namespace Sugarcrm\Sugarcrm\custom\MyLibrary;
use \Sugarcrm\Sugarcrm\Logger\Factory;
class MyCustomClass
{
public function MyCustomMethod($message = 'relax')
{
$logger = Factory::getLogger('default');
$logger->info('MyCustomClass says' . "'{$message}'");
}
}
Last modified: 2023-02-03 21:04:03 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Module_Loadable_Packages/Creating_an_Installable_Package_That_Copies_Files/index.html |
3c8c6e17daa2-0 | Creating an Installable Package that Creates New Fields
Overview
This is an overview of how to create a Module Loader package that will install custom fields to a module. This example will install a set of fields to the accounts module. The full package is downloadable here for your reference. For more details on the $manifest or $installdef options, you can visit the Introduction to the Manifest File.
Note: Sugar Sell Essentials customers do not have the ability to upload custom file packages to Sugar using Module Loader.
Manifest Example
<basepath>/manifest.php
<?php
$manifest = array(
'acceptable_sugar_flavors' => array('CE', 'PRO', 'CORP', 'ENT', 'ULT'),
'acceptable_sugar_versions' => array(
'exact_matches' => array(),
'regex_matches' => array(
0 => '6\\.5\\.(.*?)',
1 => '7\\.8\\.(.*?)\\.(.*?)',
2 => '7\\.9\\.(.*?)\\.(.*?)',
3 => '7\\.10\\.(.*?)\\.(.*?)'
),
'author' => 'SugarCRM',
'description' => 'Installs a sample set of custom fields to the accounts module',
'icon' => '',
'is_uninstallable' => true,
'name' => 'Example Custom Field Installer',
'published_date' => '2015-05-11 20:45:04',
'type' => 'module',
'version' => '1.0.0',
);
$installdefs = array(
'id' => 'package_1341607504',
'language' => array(
array( | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Module_Loadable_Packages/Creating_an_Installable_Package_that_Creates_New_Fields/index.html |
3c8c6e17daa2-1 | 'language' => array(
array(
'from' => '<basepath>/Files/Language/Accounts/en_us.lang.php',
'to_module' => 'Accounts',
'language' => 'en_us'
),
),
'custom_fields' => array(
//Text
array(
'name' => 'text_field_example_c',
'label' => 'LBL_TEXT_FIELD_EXAMPLE',
'type' => 'varchar',
'module' => 'Accounts',
'help' => 'Text Field Help Text',
'comment' => 'Text Field Comment Text',
'default_value' => '',
'max_size' => 255,
'required' => false, // true or false
'reportable' => true, // true or false
'audited' => false, // true or false
'importable' => 'true', // 'true', 'false', 'required'
'duplicate_merge' => false, // true or false
),
//DropDown
array(
'name' => 'dropdown_field_example_c',
'label' => 'LBL_DROPDOWN_FIELD_EXAMPLE',
'type' => 'enum',
'module' => 'Accounts',
'help' => 'Enum Field Help Text',
'comment' => 'Enum Field Comment Text',
'ext1' => 'account_type_dom', //maps to options - specify list name
'default_value' => 'Analyst', //key of entry in specified list
'mass_update' => false, // true or false
'required' => false, // true or false
'reportable' => true, // true or false
'audited' => false, // true or false | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Module_Loadable_Packages/Creating_an_Installable_Package_that_Creates_New_Fields/index.html |
3c8c6e17daa2-2 | 'audited' => false, // true or false
'importable' => 'true', // 'true', 'false' or 'required'
'duplicate_merge' => false, // true or false
),
//MultiSelect
array(
'name' => 'multiselect_field_example_c',
'label' => 'LBL_MULTISELECT_FIELD_EXAMPLE',
'type' => 'multienum',
'module' => 'Accounts',
'help' => 'Multi-Enum Field Help Text',
'comment' => 'Multi-Enum Field Comment Text',
'ext1' => 'account_type_dom', //maps to options - specify list name
'default_value' => 'Analyst', //key of entry in specified list
'mass_update' => false, // true or false
'required' => false, // true or false
'reportable' => true, // true or false
'audited' => false, // true or false
'importable' => 'true', // 'true', 'false' or 'required'
'duplicate_merge' => false, // true or false
),
//Checkbox
array(
'name' => 'checkbox_field_example_c',
'label' => 'LBL_CHECKBOX_FIELD_EXAMPLE',
'type' => 'bool',
'module' => 'Accounts',
'default_value' => true, // true or false
'help' => 'Bool Field Help Text',
'comment' => 'Bool Field Comment',
'audited' => false, // true or false
'mass_update' => false, // true or false
'duplicate_merge' => false, // true or false
'reportable' => true, // true or false | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Module_Loadable_Packages/Creating_an_Installable_Package_that_Creates_New_Fields/index.html |
3c8c6e17daa2-3 | 'reportable' => true, // true or false
'importable' => 'true', // 'true', 'false' or 'required'
),
//Date
array(
'name' => 'date_field_example_c',
'label' => 'LBL_DATE_FIELD_EXAMPLE',
'type' => 'date',
'module' => 'Accounts',
'default_value' => '',
'help' => 'Date Field Help Text',
'comment' => 'Date Field Comment',
'mass_update' => false, // true or false
'required' => false, // true or false
'reportable' => true, // true or false
'audited' => false, // true or false
'duplicate_merge' => false, // true or false
'importable' => 'true', // 'true', 'false' or 'required'
),
//DateTime
array(
'name' => 'datetime_field_example_c',
'label' => 'LBL_DATETIME_FIELD_EXAMPLE',
'type' => 'datetime',
'module' => 'Accounts',
'default_value' => '',
'help' => 'DateTime Field Help Text',
'comment' => 'DateTime Field Comment',
'mass_update' => false, // true or false
'enable_range_search' => false, // true or false
'required' => false, // true or false
'reportable' => true, // true or false
'audited' => false, // true or false
'duplicate_merge' => false, // true or false
'importable' => 'true', // 'true', 'false' or 'required'
),
//Encrypt
array( | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Module_Loadable_Packages/Creating_an_Installable_Package_that_Creates_New_Fields/index.html |
3c8c6e17daa2-4 | ),
//Encrypt
array(
'name' => 'encrypt_field_example_c',
'label' => 'LBL_ENCRYPT_FIELD_EXAMPLE',
'type' => 'encrypt',
'module' => 'Accounts',
'default_value' => '',
'help' => 'Encrypt Field Help Text',
'comment' => 'Encrypt Field Comment',
'reportable' => true, // true or false
'audited' => false, // true or false
'duplicate_merge' => false, // true or false
'importable' => 'true', // 'true', 'false' or 'required'
),
),
);
?>
Language Example
<basepath>/Files/Language/Accounts/en_us.lang.php
<?php
$mod_strings['LBL_TEXT_FIELD_EXAMPLE'] = 'Text Field Example';
$mod_strings['LBL_DROPDOWN_FIELD_EXAMPLE'] = 'DropDown Field Example';
$mod_strings['LBL_CHECKBOX_FIELD_EXAMPLE'] = 'Checkbox Field Example';
$mod_strings['LBL_MULTISELECT_FIELD_EXAMPLE'] = 'Multi-Select Field Example';
$mod_strings['LBL_DATE_FIELD_EXAMPLE'] = 'Date Field Example';
$mod_strings['LBL_DATETIME_FIELD_EXAMPLE'] = 'DateTime Field Example';
$mod_strings['LBL_ENCRYPT_FIELD_EXAMPLE'] = 'Encrypt Field Example';
Last modified: 2023-02-03 21:04:03 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Module_Loadable_Packages/Creating_an_Installable_Package_that_Creates_New_Fields/index.html |
f19d3800dd09-0 | Creating an Installable Package for a Logic Hook
Overview
These examples will demonstrate how to create module loadable packages for logic hooks based on different scenarios.
Logic Hook File vs. Logic Hook Definition
No matter the deployment method, all logic hooks require being registered (meaning they are attached to the $hook_array array), defining the logic hook event, module, file to load, and class and function to run for that logic hook event. For all deployment options, the logic hook definition points to a file where the class and function to run is located, and this file must be copied to the instance via the copy installdefs of the manifest. The bulk of this article will focus on the various options for registering the logic hook definition via the package manifest. But all deployment strategies will assume the same logic hook definition, the same logic hook file, and will use the same copy array to move the logic hook file into the instance.
Note: More information on the $manifest or $installdef can be found in the Introduction to the Manifest .
The Logic Hook
This logic hook will install a before_save hook to the accounts module that will default the account name to 'My New Account Name ({time stamp})'. This various ways of installing this hook will be shown in the following sections.
Logic Hook Definition
<basepath>/Files/custom/Extension/Accounts/Ext/LogicHooks/account_name_hook.php
<?php
$hook_array['before_save'][] = Array(
99,
'Example Logic Hook - Updates account name',
'custom/modules/Accounts/accounts_save.php',
'Accounts_Save',
'updateAccountName'
);
Logic Hook File
<basepath>/Files/custom/modules/Accounts/accounts_save.php
<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class Accounts_Save | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Module_Loadable_Packages/Creating_an_Installable_Package_for_a_Logic_Hook/index.html |
f19d3800dd09-1 | class Accounts_Save
{
function updateAccountName($bean, $event, $arguments)
{
$bean->name = "My New Account Name (" . time() . ")";
}
}
Distributed Plugin
If the package being built is intended to be distributed to various Sugar instances as part of a distributed plugin, your logic hook definition should be created as part of the extension framework using the LogicHooks Extension, which can be done using $installdefs['logic_hooks'] in the package manifest. When using this extension, the logic hook will be installed and uninstalled along with the plugin.
Note: More information on the $installdefs['logic_hooks'] can be found in LogicHooks Extensions.
Package Example
The following files are relative to the root of the .zip archive which is referred to at the basepath. This example package can be downloaded here.
<basepath>/manifest.php
<?php
$manifest = array(
'acceptable_sugar_flavors' => array(
'PRO',
'ENT',
'ULT'
),
'acceptable_sugar_versions' => array(
'exact_matches' => array(),
'regex_matches' => array(
'13.0.*
'),
),
'author' => 'SugarCRM',
'description' => 'Installs a sample logic hook - using extension framework',
'icon' => '',
'is_uninstallable' => true,
'name' => 'Example Logic Hook Installer - Using Extension Framework',
'published_date' => '2018-01-01 00:00:00',
'type' => 'module',
'version' => '1.0.0',
);
$installdefs = array( | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Module_Loadable_Packages/Creating_an_Installable_Package_for_a_Logic_Hook/index.html |
f19d3800dd09-2 | );
$installdefs = array(
'id' => 'package_123',
'copy' => array(
array(
'from' => '<basepath>/Files/custom/modules/Accounts/accounts_save.php',
'to' => 'custom/modules/Accounts/accounts_save.php',
),
),
'hookdefs' => array(
array(
'from' => '<basepath>/Files/custom/Extension/Accounts/Ext/LogicHooks/account_name_hook.php',
'to_module' => 'Accounts',
)
),
);
<basepath>/Files/custom/Extension/Accounts/Ext/LogicHooks/account_name_hook.php
<?php
$hook_array['before_save'][] = Array(
99,
'Example Logic Hook - Updates account name',
'custom/modules/Accounts/accounts_save.php',
'Accounts_Save',
'updateAccountName'
);
<basepath>/Files/custom/modules/Accounts/accounts_save.php
<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class Accounts_Save
{
function updateAccountName($bean, $event, $arguments)
{
$bean->name = "My New Account Name (" . time() . ")";
}
}
Promotion Process
If the package being built is intended to be part of a code promotion process, you are welcome to use the LogicHooks Extension as mentioned above or you may find it easier to update the ./custom/modules/<module>/logic_hooks.php file, which can be done using the $installdefs['logic_hooks'] in the package manifest.
Package Example | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Module_Loadable_Packages/Creating_an_Installable_Package_for_a_Logic_Hook/index.html |
f19d3800dd09-3 | Package Example
The following files are relative to the root of the .zip archive which is referred to at the basepath. This example package can be downloaded here.
<basepath>/manifest.php
<?php
$manifest = array(
'acceptable_sugar_flavors' => array(
'PRO',
'ENT',
'ULT'
),
'acceptable_sugar_versions' => array(
'exact_matches' => array(),
'regex_matches' => array(
'13.0.*
'),
),
'author' => 'SugarCRM',
'description' => 'Installs a sample logic hook - using logic_hooks installdefs',
'icon' => '',
'is_uninstallable' => true,
'name' => 'Example Logic Hook Installer - Using logic_hooks installdefs',
'published_date' => '2018-01-01 00:00:00',
'type' => 'module',
'version' => '1.0.0',
);
$installdefs = array(
'id' => 'package_456',
'copy' => array(
array(
'from' => '<basepath>/Files/custom/modules/Accounts/accounts_save.php',
'to' => 'custom/modules/Accounts/accounts_save.php',
),
),
'logic_hooks' => array(
array(
'module' => 'Accounts',
'hook' => 'before_save',
'order' => 99,
'description' => 'Example Logic Hook - Updates account name',
'file' => 'custom/modules/Accounts/accounts_save.php',
'class' => 'Accounts_Save', | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Module_Loadable_Packages/Creating_an_Installable_Package_for_a_Logic_Hook/index.html |
f19d3800dd09-4 | 'class' => 'Accounts_Save',
'function' => 'updateAccountName',
),
),
);
<basepath>/Files/custom/modules/Accounts/accounts_save.php
<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class Accounts_Save
{
function updateAccountName($bean, $event, $arguments)
{
$bean->name = "My New Account Name (" . time() . ")";
}
}
Conditionally Add or Remove Logic Hook via post_execute script
A developer may want to be able to trigger the addition or removal of logic hooks from a customization. This can be done using a post execute script with the check_logic_hook_file and remove_logic_hook_file functions.
It is recommended to be cautious when doing this and limit any updates to off-hours as not to affect system behavior for users.
Note: remove_logic_hook_file only removes hooks defined in the given module's logic_hooks.php file. check_logic_hook_file only checks hooks defined in the given module's logic_hooks.php file. Neither check or remove hooks defined via the Logic Hook Extension framework. Thus this deployment option should be considered a subset of the Promotion Process deployment option listed earlier.
Package Example
Note: For demonstration purposes, in the post_execute script, the Accounts_Save logic hook from the earlier example package is unregistered (if it exists) and a second logic hook Accounts_Save_Enterprise is registered. The second logic hook points to a different logic hook file, which is moved to the instance using copy in the manifest.
The following files are relative to the root of the .zip archive which is referred to at the basepath. This example package can be downloaded here.
<basepath>/manifest.php
<?php | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Module_Loadable_Packages/Creating_an_Installable_Package_for_a_Logic_Hook/index.html |
f19d3800dd09-5 | <basepath>/manifest.php
<?php
$manifest = array(
'acceptable_sugar_flavors' => array(
'PRO',
'ENT',
'ULT'
),
'acceptable_sugar_versions' => array(
'exact_matches' => array(),
'regex_matches' => array(
'13.0.*
'),
),
'author' => 'SugarCRM',
'description' => 'Installs a sample logic hook - using post_execute check_logic_hook_file',
'icon' => '',
'is_uninstallable' => true,
'name' => 'Example Logic Hook Installer - Using post_execute check_logic_hook_file',
'published_date' => '2018-01-01 00:00:00',
'type' => 'module',
'version' => '1.0.0',
);
$installdefs = array(
'id' => 'package_789',
'copy' => array(
array(
'from' => '<basepath>/Files/custom/modules/Accounts/accounts_save_enterprise.php',
'to' => 'custom/modules/Accounts/accounts_save_enterprise.php',
),
),
'post_execute' => array(
'<basepath>/change_hooks.php',
),
);
<basepath>/Files/custom/modules/Accounts/accounts_save_enterprise.php
<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class Accounts_Save_Enterprise
{
function updateAccountName($bean, $event, $arguments)
{
$bean->name = "My New Account Name (" . time() . ") -- Enterprise";
}
} | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Module_Loadable_Packages/Creating_an_Installable_Package_for_a_Logic_Hook/index.html |
f19d3800dd09-6 | }
}
<basepath>/change_hooks.php
<?php
if(!defined('sugarEntry')) define('sugarEntry', true);
require_once 'include/entryPoint.php';
$accounts_hook_pro = array(
99,
'Example Logic Hook - Updates account name',
'custom/modules/Accounts/accounts_save.php',
'Accounts_Save',
'updateAccountName'
);
$accounts_hook_ent = array(
99,
'Example Logic Hook - Updates account name - Enterprise',
'custom/modules/Accounts/accounts_save_enterprise.php',
'Accounts_Save_Enterprise',
'updateAccountName'
);
if( $GLOBALS['sugar_flavor'] == 'ENT' ) {
//unregister Accounts_Save logichook
remove_logic_hook("Accounts", "before_save", $accounts_hook_pro);
//register Accounts_Save_Enterprise logichook
check_logic_hook_file("Accounts", "before_save", $accounts_hook_ent);
}
Last modified: 2023-02-03 21:04:03 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Module_Loadable_Packages/Creating_an_Installable_Package_for_a_Logic_Hook/index.html |
69b7c71a0c17-0 | Modifying Subpanel Buttons
Overview
Several buttons exist on each subpanel by default such as "Create" (+ Plus symbol) and "Link Existing Record". These buttons are controlled by the panel-top view for each module. To make changes to the buttons included in a subpanel layout, you will need to create an override for the panel-top view in ./custom/Extension/modules/<module>/Ext/clients/base/views/panel-top/ and update the corresponding buttons property to include or exclude a button.
If you need to make changes to a specific relationships subpanel, then you will need to modify the subpanels layout definition for the relationship to point to a custom panel-top view that you define.
Steps to Complete
Editing Subpanel Buttons
In this example, we will remove the "Create" button from the Contacts subpanel for all modules. This code snippet uses the same button definition that the create button uses. It has been changed to trigger the "Link Existing Record" action by setting the button type to link-action. The blank array after the initial button is just to assure that the drop-down button displays next to it as disabled for placement purposes.
Create the file custom/Extension/modules/Contacts/Ext/clients/base/views/panel-top/panel-top.php as follows: <?php
$viewdefs['Contacts']['base']['view']['panel-top']['buttons'] = array(
array(
'type' => 'actiondropdown',
'name' => 'panel_dropdown',
'css_class' => 'pull-right',
'buttons' => array(
array(
'type' => 'link-action',
'icon' => 'fa-link',
'name' => 'select_button',
'label' => ' ',
'tooltip' => 'LBL_ASSOC_RELATED_RECORD',
),
array(
),
), | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Modifying_Subpanel_Action_Buttons/index.html |
69b7c71a0c17-1 | ),
array(
),
),
),
);
Navigate to Admin > Repair and click "Quick Repair and Rebuild".
The subpanel will appear as shown below for all Contacts subpanels.
Using a Custom Panel-Top View for a Specific Relationship
In this example, we will only remove the "Create" action from a specific relationships subpanel. Specifically, the example will look at Contacts subpanel on the Accounts module and implement the above changes explicitly for that relationship.
Create the custom panel-top view in ./custom/modules/Contacts/clients/base/views/panel-top-for-accounts/panel-top-for-accounts.php as follows: <?php
$viewdefs['Contacts']['base']['view']['panel-top-for-accounts'] = array(
'type' => 'panel-top',
'template' => 'panel-top',
'buttons' => array(
array(
'type' => 'actiondropdown',
'name' => 'panel_dropdown',
'css_class' => 'pull-right',
'buttons' => array(
array(
'type' => 'link-action',
'icon' => 'fa-link',
'name' => 'select_button',
'label' => ' ',
'tooltip' => 'LBL_ASSOC_RELATED_RECORD',
),
array(
),
),
),
),
);
Create the subpanel panel-top override definition for Accounts in ./custom/modules/Accounts/clients/base/layouts/subpanels/subpanels.php as follows:Â
<?php
require 'modules/Accounts/clients/base/layouts/subpanels/subpanels.php';
foreach($viewdefs['Accounts']['base']['layout']['subpanels']['components'] as $key => $component){
if ($component['context']['link'] == 'contacts'){ | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Modifying_Subpanel_Action_Buttons/index.html |
69b7c71a0c17-2 | if ($component['context']['link'] == 'contacts'){
$viewdefs['Accounts']['base']['layout']['subpanels']['components'][$key]['override_paneltop_view'] = 'panel-top-for-accounts';
break;
}
}
Navigate to Admin > Repair and click "Quick Repair and Rebuild".
Your changes will now be reflected in the system.
Last modified: 2023-02-03 21:04:03 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Modifying_Subpanel_Action_Buttons/index.html |
2a07a052b3fe-0 | Adding an Existing Note to an Email as Attachment
Overview
There may be times when you want to reuse a file attached to one Note record as an attachment for an Email, similar to the ability in the Compose Email view to add an attachment using 'Sugar Document'.
Key Concepts
There are two key things to understand when implementing this functionality:
You can not relate an existing Note record to an Email record. This will throw an Exception in the API as intended. A note that is used as an attachment can only exist once and can not act as an attachment across multiple emails.
You can create a new Note record that uses an existing Note's attached file. Doing so essentially requires setting the upload_id field of the new Note record to the id of the existing Note you want to reuse the file from, and setting the file_source field of the new Note to 'Notes'. In addition to needing to set the upload_id, you must also set the filename and name field.
The following examples demonstrate how to do this in three different contexts: server-side (SugarBean/PHP), client-side (sidecar/Javascript), and purely through the API. But all three contexts follow the same essential steps:
Fetch the original Note record;
Create a new Note record, setting the necessary fields from the original Note record;
Link the new Note record to the Email record via the appropriate 'attachments' link.
PHP
This example would be done server-side using the SugarBean object, similar to how you might interact with the records in a custom Logic Hook or Scheduler job.
$original_note_id = '4e226282-8158-11e8-a1b3-439fe19c087a';
$email_id = 'e3e058f4-7f11-11e8-ba11-fcdd97d61bbe';
// 1. Fetch Original Note: | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_an_Existing_Note_to_an_Email_as_Attachment/index.html |
2a07a052b3fe-1 | // 1. Fetch Original Note:
$original_note = BeanFactory::retrieveBean('Notes', $original_note_id);
// 2. Create a new note based on original note, setting upload_id, name, and filename:
$new_note = BeanFactory::newBean('Notes');
$new_note->upload_id = $original_note->getUploadId();
$new_note->file_source = 'Notes';
$new_note->filename = $original_note->filename;
$new_note->name = $original_note->filename;
// 3. Relate the new note to Email record using 'attachments' link:
$email = BeanFactory::retrieveBean('Emails', $email_id);
$email->load_relationship('attachments');
$email->attachments->add($email, $new_note);
Note that in most contexts, such as a Logic Hook or a custom endpoint, you will not need to call save() on either the $new_note or $email for $new_note to be related as an attachment to $email and for $new_note to save. The $new_note record will save as part of being linked to $email.
Javascript
The following example is totally standalone within Sidecar, demonstrating how to fetch the existing Note using app.data.createBean and bean.fetch(), create the new Note using app.data.createBean and setting the relevant fields, and then adding the new Note to the email records attachments_collection.
var original_note_id = '4e226282-8158-11e8-a1b3-439fe19c087a';
var email_id = 'e3e058f4-7f11-11e8-ba11-fcdd97d61bbe';
// 1. Fetch Original Note:
var original_note = app.data.createBean('Notes');
original_note.set('id', original_note_id);
original_note.fetch(); | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_an_Existing_Note_to_an_Email_as_Attachment/index.html |
2a07a052b3fe-2 | original_note.set('id', original_note_id);
original_note.fetch();
// 2. Create a new note based on original note, setting upload_id, name, and filename:
var new_note = app.data.createBean('Notes', {
_link: 'attachments',
upload_id: original_note.get('id'),
file_source: 'Notes',
filename: original_note.get('filename'),
name: original_note.get('filename'),
file_mime_type: original_note.get('file_mime_type'),
file_size: original_note.get('file_size'),
file_ext: original_note.get('file_ext'),
});
// 3. Relate the new note to Email record using 'attachments_collection' link:
var email = app.data.createBean('Emails');
email.set('id', email_id);
email.fetch();
email.get('attachments_collection').add(new_note,{merge:true});
email.save();
Note: In the above example, the fields file_mime_type, file_size, and file_ext are also set. This is assuming a context where the customization is adding the attachments to the Compose Email view. Setting these fields makes the new attachments look correct to the user before saving the Email, but these fields are otherwise set automatically on save. If extending the actual compose view for emails, you also wouldn't fetch the email directly. This is added in this example purely for demonstration purposes.
REST API
The following section will outline how to related the attachment using the REST API using the /link/attachments/Â endpoint for the Email record.
Fetch Original Note
To fetch the original note, send a GET request to rest/{REST VERSION}/Notes/{$original_note_id}. An example of the response is shown below :
{
"id": "4e226282-8158-11e8-a1b3-439fe19c087a", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_an_Existing_Note_to_an_Email_as_Attachment/index.html |
2a07a052b3fe-3 | "name": "Note with Attachment",
"date_entered": "2018-07-01T12:00:00-00:00",
"description": "Send to special clients.",
"file_mime_type": "application/pdf",
"filename": "special_sales_doc.pdf",
"_module": "Notes"
}
Create and Relate a Note
Create a JSON object based on the response (which we will treat as a JSON object named $original_note) like:
{
"upload_id": "$original_note.id",
"file_source" : "Notes"
"name" : "$original_note.filename",
"filename" : "$original_note.filename",
}
Relate the Note to the Email record using the 'attachments' link. Next, send a POST request to rest/{REST VERSION}/Emails/{$email_id}/link/attachments/Â with the JSON shown above as the request body.
Last modified: 2023-02-03 21:04:03 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_an_Existing_Note_to_an_Email_as_Attachment/index.html |
12870e1f882e-0 | Adding Buttons to the Record View
Overview
This example explains how to create additional buttons on the record view and add events. We will extend and override the stock Accounts record view to add a custom button. The custom button will be called "Validate Postal Code" and ping the Zippopotamus REST service to validate the records billing state and postal code.
Steps To Complete
This tutorial requires the following steps, which are explained in the sections below:
Defining the Metadata
Adding Custom Buttons
Defining the Button Label
Extending and Overriding the Controller
Defining the Metadata
To add a button to the record view, you will first need to create the custom metadata for the view if it doesn't exist. You can easily do this by opening and saving your modules record layout in studio. Depending on your module, the path will then be ./custom/modules/<module>/clients/base/views/record/record.php. Once your file is in place, you will need to copy the button array from ./clients/base/views/record/record.php and add it to the $viewdefs['<module>']['base']['view']['record'] portion of your metadata array. An example of the button array is shown below:
'buttons' => array(
array(
'type' => 'button',
'name' => 'cancel_button',
'label' => 'LBL_CANCEL_BUTTON_LABEL',
'css_class' => 'btn-invisible btn-link',
'showOn' => 'edit',
),
array(
'type' => 'rowaction',
'event' => 'button:save_button:click',
'name' => 'save_button',
'label' => 'LBL_SAVE_BUTTON_LABEL',
'css_class' => 'btn btn-primary',
'showOn' => 'edit', | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_Buttons_to_the_Record_View/index.html |
12870e1f882e-1 | 'showOn' => 'edit',
'acl_action' => 'edit',
),
array(
'type' => 'actiondropdown',
'name' => 'main_dropdown',
'primary' => true,
'showOn' => 'view',
'buttons' => array(
array(
'type' => 'rowaction',
'event' => 'button:edit_button:click',
'name' => 'edit_button',
'label' => 'LBL_EDIT_BUTTON_LABEL',
'acl_action' => 'edit',
),
array(
'type' => 'shareaction',
'name' => 'share',
'label' => 'LBL_RECORD_SHARE_BUTTON',
'acl_action' => 'view',
),
array(
'type' => 'pdfaction',
'name' => 'download-pdf',
'label' => 'LBL_PDF_VIEW',
'action' => 'download',
'acl_action' => 'view',
),
array(
'type' => 'pdfaction',
'name' => 'email-pdf',
'label' => 'LBL_PDF_EMAIL',
'action' => 'email',
'acl_action' => 'view',
),
array(
'type' => 'divider',
),
array(
'type' => 'rowaction',
'event' => 'button:find_duplicates_button:click',
'name' => 'find_duplicates_button',
'label' => 'LBL_DUP_MERGE',
'acl_action' => 'edit',
),
array(
'type' => 'rowaction', | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_Buttons_to_the_Record_View/index.html |
12870e1f882e-2 | ),
array(
'type' => 'rowaction',
'event' => 'button:duplicate_button:click',
'name' => 'duplicate_button',
'label' => 'LBL_DUPLICATE_BUTTON_LABEL',
'acl_module' => $module,
),
array(
'type' => 'rowaction',
'event' => 'button:audit_button:click',
'name' => 'audit_button',
'label' => 'LNK_VIEW_CHANGE_LOG',
'acl_action' => 'view',
),
array(
'type' => 'divider',
),
array(
'type' => 'rowaction',
'event' => 'button:delete_button:click',
'name' => 'delete_button',
'label' => 'LBL_DELETE_BUTTON_LABEL',
'acl_action' => 'delete',
),
),
),
array(
'name' => 'sidebar_toggle',
'type' => 'sidebartoggle',
),
),
Note: When copying this array into your metadata, you will need to replace $module with the text string of your module's name.
For standard button types, the button definitions will contain the following properties:
Property
Potential Values
Description
type
button, rowaction, shareaction, actiondropdown
The widget type
name
Â
The name of the button
label
Â
The label string key for the display text of the button
css_class
Â
The CSS class to append to the button
showOn
edit, view
The ACL action of the button | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_Buttons_to_the_Record_View/index.html |
12870e1f882e-3 | showOn
edit, view
The ACL action of the button
For this example, we will add the custom button to the main dropdown. For actiondropdown types, there is an additional buttons array for you to specify the dropdown list of buttons. The button definitions in this array will contain the following properties:
Property
Potential Values
Description
type
button, rowaction, shareaction, actiondropdown
The widget type; Most custom buttons are 'rowaction'
event
button:button_name:click
The event name of the button
name
Â
The name of the button
label
Â
The label string key for the display text of the button
acl_action
 edit, view
The ACL action of the button
Adding Custom Buttons
For this example, modify the accounts' metadata to add the button definition to main_dropdown:
array(
'type' => 'rowaction',
'event' => 'button:validate_postal_code:click',
'name' => 'validate_postal_code',
'label' => 'LBL_VALIDATE_POSTAL_CODE',
'acl_action' => 'view',
),
A full example is shown below:
./custom/modules/Accounts/clients/base/views/record/record.php
<?php
$viewdefs['Accounts'] =
array (
'base' =>
array (
'view' =>
array (
'record' =>
array (
'buttons' =>
array (
0 =>
array (
'type' => 'button',
'name' => 'cancel_button',
'label' => 'LBL_CANCEL_BUTTON_LABEL',
'css_class' => 'btn-invisible btn-link',
'showOn' => 'edit',
),
1 => | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_Buttons_to_the_Record_View/index.html |
12870e1f882e-4 | 'showOn' => 'edit',
),
1 =>
array (
'type' => 'rowaction',
'event' => 'button:save_button:click',
'name' => 'save_button',
'label' => 'LBL_SAVE_BUTTON_LABEL',
'css_class' => 'btn btn-primary',
'showOn' => 'edit',
'acl_action' => 'edit',
),
2 =>
array (
'type' => 'actiondropdown',
'name' => 'main_dropdown',
'primary' => true,
'showOn' => 'view',
'buttons' =>
array (
0 =>
array (
'type' => 'rowaction',
'event' => 'button:edit_button:click',
'name' => 'edit_button',
'label' => 'LBL_EDIT_BUTTON_LABEL',
'acl_action' => 'edit',
),
1 =>
array (
'type' => 'shareaction',
'name' => 'share',
'label' => 'LBL_RECORD_SHARE_BUTTON',
'acl_action' => 'view',
),
2 =>
array (
'type' => 'rowaction',
'event' => 'button:validate_postal_code:click',
'name' => 'validate_postal_code',
'label' => 'LBL_VALIDATE_POSTAL_CODE',
'acl_action' => 'view',
),
3 =>
array (
'type' => 'divider',
),
4 =>
array (
'type' => 'rowaction', | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_Buttons_to_the_Record_View/index.html |
12870e1f882e-5 | 4 =>
array (
'type' => 'rowaction',
'event' => 'button:duplicate_button:click',
'name' => 'duplicate_button',
'label' => 'LBL_DUPLICATE_BUTTON_LABEL',
'acl_module' => 'Accounts',
),
5 =>
array (
'type' => 'rowaction',
'event' => 'button:audit_button:click',
'name' => 'audit_button',
'label' => 'LNK_VIEW_CHANGE_LOG',
'acl_action' => 'view',
),
6 =>
array (
'type' => 'divider',
),
7 =>
array (
'type' => 'rowaction',
'event' => 'button:delete_button:click',
'name' => 'delete_button',
'label' => 'LBL_DELETE_BUTTON_LABEL',
'acl_action' => 'delete',
),
),
),
3 =>
array (
'name' => 'sidebar_toggle',
'type' => 'sidebartoggle',
),
),
'panels' =>
array (
0 =>
array (
'name' => 'panel_header',
'header' => true,
'fields' =>
array (
0 =>
array (
'name' => 'picture',
'type' => 'avatar',
'width' => 42,
'height' => 42,
'dismiss_label' => true,
'readonly' => true,
),
1 => 'name',
2 =>
array ( | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_Buttons_to_the_Record_View/index.html |
12870e1f882e-6 | ),
1 => 'name',
2 =>
array (
'name' => 'favorite',
'label' => 'LBL_FAVORITE',
'type' => 'favorite',
'dismiss_label' => true,
),
3 =>
array (
'name' => 'follow',
'label' => 'LBL_FOLLOW',
'type' => 'follow',
'readonly' => true,
'dismiss_label' => true,
),
),
),
1 =>
array (
'name' => 'panel_body',
'columns' => 2,
'labelsOnTop' => true,
'placeholders' => true,
'fields' =>
array (
0 => 'website',
1 => 'industry',
2 => 'parent_name',
3 => 'account_type',
4 => 'assigned_user_name',
5 => 'phone_office',
),
),
2 =>
array (
'name' => 'panel_hidden',
'hide' => true,
'columns' => 2,
'labelsOnTop' => true,
'placeholders' => true,
'fields' =>
array (
0 =>
array (
'name' => 'fieldset_address',
'type' => 'fieldset',
'css_class' => 'address',
'label' => 'LBL_BILLING_ADDRESS',
'fields' =>
array (
0 =>
array (
'name' => 'billing_address_street',
'css_class' => 'address_street', | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_Buttons_to_the_Record_View/index.html |
12870e1f882e-7 | 'css_class' => 'address_street',
'placeholder' => 'LBL_BILLING_ADDRESS_STREET',
),
1 =>
array (
'name' => 'billing_address_city',
'css_class' => 'address_city',
'placeholder' => 'LBL_BILLING_ADDRESS_CITY',
),
2 =>
array (
'name' => 'billing_address_state',
'css_class' => 'address_state',
'placeholder' => 'LBL_BILLING_ADDRESS_STATE',
),
3 =>
array (
'name' => 'billing_address_postalcode',
'css_class' => 'address_zip',
'placeholder' => 'LBL_BILLING_ADDRESS_POSTALCODE',
),
4 =>
array (
'name' => 'billing_address_country',
'css_class' => 'address_country',
'placeholder' => 'LBL_BILLING_ADDRESS_COUNTRY',
),
),
),
1 =>
array (
'name' => 'fieldset_shipping_address',
'type' => 'fieldset',
'css_class' => 'address',
'label' => 'LBL_SHIPPING_ADDRESS',
'fields' =>
array (
0 =>
array (
'name' => 'shipping_address_street',
'css_class' => 'address_street',
'placeholder' => 'LBL_SHIPPING_ADDRESS_STREET',
),
1 =>
array (
'name' => 'shipping_address_city',
'css_class' => 'address_city',
'placeholder' => 'LBL_SHIPPING_ADDRESS_CITY',
),
2 =>
array ( | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_Buttons_to_the_Record_View/index.html |
12870e1f882e-8 | ),
2 =>
array (
'name' => 'shipping_address_state',
'css_class' => 'address_state',
'placeholder' => 'LBL_SHIPPING_ADDRESS_STATE',
),
3 =>
array (
'name' => 'shipping_address_postalcode',
'css_class' => 'address_zip',
'placeholder' => 'LBL_SHIPPING_ADDRESS_POSTALCODE',
),
4 =>
array (
'name' => 'shipping_address_country',
'css_class' => 'address_country',
'placeholder' => 'LBL_SHIPPING_ADDRESS_COUNTRY',
),
5 =>
array (
'name' => 'copy',
'label' => 'NTC_COPY_BILLING_ADDRESS',
'type' => 'copy',
'mapping' =>
array (
'billing_address_street' => 'shipping_address_street',
'billing_address_city' => 'shipping_address_city',
'billing_address_state' => 'shipping_address_state',
'billing_address_postalcode' => 'shipping_address_postalcode',
'billing_address_country' => 'shipping_address_country',
),
),
),
),
2 =>
array (
'name' => 'phone_alternate',
'label' => 'LBL_OTHER_PHONE',
),
3 => 'email',
4 => 'phone_fax',
5 => 'campaign_name',
6 =>
array (
'name' => 'description',
'span' => 12,
),
7 => 'sic_code',
8 => 'ticker_symbol',
9 => 'annual_revenue', | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_Buttons_to_the_Record_View/index.html |
12870e1f882e-9 | 8 => 'ticker_symbol',
9 => 'annual_revenue',
10 => 'employees',
11 => 'ownership',
12 => 'rating',
13 =>
array (
'name' => 'date_entered_by',
'readonly' => true,
'type' => 'fieldset',
'label' => 'LBL_DATE_ENTERED',
'fields' =>
array (
0 =>
array (
'name' => 'date_entered',
),
1 =>
array (
'type' => 'label',
'default_value' => 'LBL_BY',
),
2 =>
array (
'name' => 'created_by_name',
),
),
),
14 => 'team_name',
15 =>
array (
'name' => 'date_modified_by',
'readonly' => true,
'type' => 'fieldset',
'label' => 'LBL_DATE_MODIFIED',
'fields' =>
array (
0 =>
array (
'name' => 'date_modified',
),
1 =>
array (
'type' => 'label',
'default_value' => 'LBL_BY',
),
2 =>
array (
'name' => 'modified_by_name',
),
),
'span' => 12,
),
),
),
),
'templateMeta' =>
array (
'useTabs' => false,
'tabDefs' =>
array (
'LBL_RECORD_BODY' =>
array ( | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_Buttons_to_the_Record_View/index.html |
12870e1f882e-10 | array (
'LBL_RECORD_BODY' =>
array (
'newTab' => false,
'panelDefault' => 'expanded',
),
'LBL_RECORD_SHOWMORE' =>
array (
'newTab' => false,
'panelDefault' => 'expanded',
),
),
),
),
),
),
);
Defining the Button Label
Next, define the label for the button:
./custom/Extension/modules/Accounts/Ext/Language/en_us.validatePostalCode.php
<?php
$mod_strings['LBL_VALIDATE_POSTAL_CODE'] = 'Validate Postal Code';
Extending and Overriding the Controller
Once the button has been added to the metadata, extend and override the record view controller:
./custom/modules/Accounts/clients/base/views/record/record.js
({
extendsFrom: 'RecordView',
zipJSON: {},
initialize: function (options) {
this._super('initialize', [options]);
//add listener for custom button
this.context.on('button:validate_postal_code:click', this.validate_postal_code, this);
},
validate_postal_code: function() {
//example of getting field data from current record
var AcctID = this.model.get('id');
var currentCity = this.model.get('billing_address_city');
var currentZip = this.model.get('billing_address_postalcode');
//jQuery AJAX call to Zippopotamus REST API
$.ajax({
url: 'http://api.zippopotam.us/us/' + currentZip,
success: function(data) {
this.zipJSON = data;
var city = this.zipJSON.places[0]['place name'];
if (city === currentCity) | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_Buttons_to_the_Record_View/index.html |
12870e1f882e-11 | if (city === currentCity)
{
app.alert.show('address-ok', {
level: 'success',
messages: 'City and Zipcode match.',
autoClose: true
});
}
else
{
app.alert.show('address-ok', {
level: 'error',
messages: 'City and Zipcode do not match.',
autoClose: false
});
}
}
});
}
})
Once the files are in place, navigate to Admin > Repair > Quick Repair and Rebuild.
Adding Buttons without Overriding View Controllers
Sometimes your customization might need to add the same buttons to multiple views, but you don't want to overwrite other possible customizations already on the view. The following will walk through creating a custom button like the above example, add adding the buttons to views without overriding the module view controllers.
Create a Custom Button
Buttons typically come in two forms, a standard button and a 'rowaction' in an Action Menu. We can create two buttons to handle both scenarios.
./clients/base/fields/zipcode-check-button/zipcode-check-button.js
/**
* Zipcode Check button will check if zipcode matches city field
*
* @class View.Fields.Base.ZipcodeCheckButtonField
* @alias SUGAR.App.view.fields.BaseZipcodeCheckButtonField
* @extends View.Fields.Base.ButtonField
*/
({
extendsFrom: 'ButtonField',
defaultZipCodeField: 'billing_address_postalcode',
defaultCityField: 'billing_address_city',
/**
* @inheritdoc
*/
initialize: function(options) {
options.def.events = _.extend({}, options.def.events, {
'click .zip-check-btn': 'validatePostalCode'
}); | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_Buttons_to_the_Record_View/index.html |
12870e1f882e-12 | 'click .zip-check-btn': 'validatePostalCode'
});
this._super('initialize', [options]);
this.def.zip_code_field = _.isEmpty(this.def.zip_code_field)?this.defaultZipCodeField:this.def.zip_code_field;
this.def.city_field = _.isEmpty(this.def.city_field)?this.defaultCityField:this.def.city_field;
},
validatePostalCode: function(evt) {
var currentCity = this.model.get(this.def.city_field);
var currentZip = this.model.get(this.def.zip_code_field);
//jQuery AJAX call to Zippopotamus REST API
$.ajax({
url: 'http://api.zippopotam.us/us/' + currentZip,
success: function(data) {
this.zipJSON = data;
var city = this.zipJSON.places[0]['place name'];
if (city === currentCity)
{
app.alert.show('address-ok', {
level: 'success',
messages: 'City and Zipcode match.',
autoClose: true
});
}
else
{
app.alert.show('address-ok', {
level: 'error',
messages: 'City and Zipcode do not match.',
autoClose: false
});
}
}
});
}
})
./clients/base/fields/zipcode-check-rowaction/zipcode-check-rowaction.js
/**
* Zipcode Check button will check if zipcode matches city field
*
* @class View.Fields.Base.ZipcodeCheckRowactionField
* @alias SUGAR.App.view.fields.BaseZipcodeCheckRowactionField
* @extends View.Fields.Base.RowactionField
*/
({
extendsFrom: 'RowactionField', | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_Buttons_to_the_Record_View/index.html |
12870e1f882e-13 | */
({
extendsFrom: 'RowactionField',
defaultZipCodeField: 'billing_address_postalcode',
defaultCityField: 'billing_address_city',
/**
* @inheritdoc
*/
initialize: function(options) {
this._super('initialize', [options]);
this.def.zip_code_field = _.isEmpty(this.def.zip_code_field)?this.defaultZipCodeField:this.def.zip_code_field;
this.def.city_field = _.isEmpty(this.def.city_field)?this.defaultCityField:this.def.city_field;
},
/**
* Rowaction fields have a default event which calls rowActionSelect
*/
rowActionSelect: function(evt) {
this.validatePostalCode(evt);
},
validatePostalCode: function(evt) {
var currentCity = this.model.get(this.def.city_field);
var currentZip = this.model.get(this.def.zip_code_field);
//jQuery AJAX call to Zippopotamus REST API
$.ajax({
url: 'http://api.zippopotam.us/us/' + currentZip,
success: function(data) {
this.zipJSON = data;
var city = this.zipJSON.places[0]['place name'];
if (city === currentCity)
{
app.alert.show('address-check-msg', {
level: 'success',
messages: 'City and Zipcode match.',
autoClose: true
});
}
else
{
app.alert.show('address-check-msg', {
level: 'error',
messages: 'City and Zipcode do not match.',
autoClose: false
});
}
}
});
}
}) | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_Buttons_to_the_Record_View/index.html |
12870e1f882e-14 | });
}
}
});
}
})
Along with the JavaScript controllers for the buttons, you can copy over the detail.hbs and edit.hbs from the base controllers that each button is extended from into each folder. The folder structure will look as follows:
./clients/base/fields/zipcode-check-button/
zipcode-check-button.js
detail.hbs
edit.hbs
./clients/base/fields/zipcode-check-rowaction/
zipcode-check-rowaction.js
detail.hbs
edit.hbs
 In the Handlebar files, you should add a custom CSS class called zip-check-btn to each of the layouts, as a way to find the elements on the page. This is also used for the ZipcodeCheckButton to isolate the event trigger. Example below:
./cilents/base/fields/zipcode-check-button/edit.hbs
<a href="{{#if fullRoute}}#{{fullRoute}}{{else}}{{#if def.route}}#{{buildRoute context=context model=model action=def.route.action}}{{else}}javascript:void(0);{{/if}}{{/if}}"
class="btn{{#if def.primary}} btn-primary{{/if}} zip-check-btn"
{{#if def.tooltip}}
rel="tooltip"
data-placement="bottom"
title="{{str def.tooltip module}}"
{{/if}}
{{#if ariaLabel}}aria-label="{{ariaLabel}}"{{/if}}
role="button" tabindex="{{tabIndex}}" name="{{name}}">{{#if def.icon}}<i class="fa {{def.icon}}"></i> {{/if}}{{label}}</a>
Once we have the button controllers and the templates setup, we can add the buttons to the View metadata for particular modules.
Appending Buttons to Metadata | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_Buttons_to_the_Record_View/index.html |
12870e1f882e-15 | Appending Buttons to Metadata
After creating your buttons, you will need to append the buttons to the views metadata. For this, you can use the Extension Framework. The following examples will add a button to the action menu on the Accounts record view and a button to the Contacts record view. Please note that this example assumes that you have created the rowaction button above.
./custom/Extension/modules/Accounts/Ext/clients/base/views/record/addZipCodeCheckRowaction.php
$buttons = isset($viewdefs['Accounts']['base']['view']['record']['buttons'])?$viewdefs['Accounts']['base']['view']['record']['buttons']:array();
if (!empty($buttons)) {
foreach ($buttons as $key => $button) {
if ($button['type'] == 'actiondropdown' && $button['name'] == 'main_dropdown') {
$viewdefs['Accounts']['base']['view']['record']['buttons'][$key]['buttons'][] = array(
'type' => 'divider',
);
$viewdefs['Accounts']['base']['view']['record']['buttons'][$key]['buttons'][] = array(
'type' => 'zipcode-check-rowaction',
'event' => 'button:zipcode_check:click',
'name' => 'zipcode_check_button',
'label' => 'LBL_ZIPCODE_CHECK_BUTTON_LABEL',
'acl_action' => 'edit',
'showOn' => 'view',
);
break;
}
}
}
./custom/Extension/modules/Contacts/Ext/clients/base/views/record/addZipCodeCheckButton.php
$buttons = isset($viewdefs['Contacts']['base']['view']['record']['buttons'])?$viewdefs['Contacts']['base']['view']['record']['buttons']:array();
$zipCodeButton = array ( | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_Buttons_to_the_Record_View/index.html |
12870e1f882e-16 | $zipCodeButton = array (
'type' => 'zipcode-check-button',
'event' => 'button:zipcode_check:click',
'name' => 'zipcode_check_button',
'label' => 'LBL_ZIPCODE_CHECK_BUTTON_LABEL',
'acl_action' => 'edit',
'zip_code_field' => 'primary_address_postalcode',
'city_field' => 'primary_address_city'
);
if (!empty($buttons)){
foreach($buttons as $key => $button){
if ($button['type'] == 'actiondropdown' && $button['name'] == 'main_dropdown'){
//Get everything from this point down
$slicedBtns = array_slice($viewdefs['Contacts']['base']['view']['record']['buttons'],$key);
//Remove everything from this point down
array_splice($viewdefs['Contacts']['base']['view']['record']['buttons'],$key);
//Add Zip Code Button
$viewdefs['Contacts']['base']['view']['record']['buttons'][] = $zipCodeButton;
//Add back the buttons we removed
foreach($slicedBtns as $oldButton){
$viewdefs['Contacts']['base']['view']['record']['buttons'][] = $oldButton;
}
break;
}
}
} else {
$viewdefs['Contacts']['base']['view']['record']['buttons'] = array(
$zipCodeButton
);
}
unset($zipCodeButton);
The last thing that is needed now, is to define the button's label.
Defining the Button Labels
Since the button was made to work globally on multiple modules, we can define the label at the application level.
./custom/Extension/application/Ext/Language/en_us.ZipCodeCheckButton.php | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_Buttons_to_the_Record_View/index.html |
12870e1f882e-17 | ./custom/Extension/application/Ext/Language/en_us.ZipCodeCheckButton.php
$app_strings['LBL_ZIPCODE_CHECK_BUTTON_LABEL'] = 'Verify Zip Code';
 Once all files are in place, you can run a Quick Repair and Rebuild and the buttons will display and check the Zipcode fields for both the Contacts and Accounts record views without having to extend either modules RecordView controllers.
Last modified: 2023-02-03 21:04:03 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Adding_Buttons_to_the_Record_View/index.html |
97d93edc28d1-0 | Removing the Account Requirement on Opportunities
Overview
This article covers how to remove the Account field from being required on the Opportunities module.Â
Removing the Requirement in Configuration
By default, Sugar requires the accounts field to be populated on several modules. These modules include
Opportunities
Cases
Contracts
In order to remove this dependency, you will need to modify the require_accounts configuration in your ./config_override.php.
$sugar_config['require_accounts'] = false;
The resulting file should look similar to:
Removing the Requirement in Vardefs
Once you have updated your configuration, you may find the field is still required. This may be due to the module's vardefs array having the field's required attribute set to true. This will also need to be updated. Using the Opportunities vardefs as an example, we will need to do the following:
Create a custom file in the Opportunities Extension directory like ./custom/Extension/modules/Opportunities/Ext/Vardefs/no_account_required.phpÂ
Set the content of this file so that the account_name field has required set to false
<?php
$dictionary['Opportunity']['fields']['account_name']['required'] = false;
Once completed, you will need to navigate to Admin > Repairs and run a Quick Repair & Rebuild
Removing the Requirement in View Metadata
If the Account field is still required after making these changes, this may be due to the views metadata having the field's required attribute set to true. By default, account_name should not be set to required, but if you have created custom views, these may need to be updated. Using the Opportunities record view as an example, we will need to do the following:
Edit  ./custom/modules/Opportunities/clients/base/views/record/record.php with a text editor application. | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Removing_the_Account_Requirement_on_Opportunities/index.html |
97d93edc28d1-1 | Search for the account_name field in panel definitions of your record view.
Remove 'required' => true, from the account_name definition. If it doesn't already exist, you don't need to modify anything.
...
'fields' =>
array (
0 =>
array (
'name' => 'account_name',
'required' => false,
...
Your resulting file should be:
...
'fields' =>
array (
0 =>
array (
'name' => 'account_name',
...
These changes will only affect the record view for Opportunities. You may need to modify additional module layouts based on your use case. A list of other views you many need to modify for your module are shown below.
./custom/modules/<module>/clients/base/views/list/list.php
./custom/modules/<module>/clients/base/views/record/record.php
./custom/modules/<module>/clients/base/views/dupecheck-list/dupecheck-list.php
./custom/modules/<module>/clients/base/views/resolve-conflicts-list/resolve-conflicts-list.php
./custom/modules/<module>/clients/base/views/selection-list/selection-list.php
./custom/modules/<module>/clients/base/views/subpanel-list/subpanel-list.php
Once completed, you will need to navigate to Admin > Repairs and run a Quick Repair & Rebuild
Application
Now that the appropriate changes have been made, navigate to the Opportunities module and create a new opportunity record. You will notice that the Account Name field no longer indicates "Required" in the field. In addition, the Account Name field will no longer be marked as required when importing records into the Opportunities module. | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Removing_the_Account_Requirement_on_Opportunities/index.html |
97d93edc28d1-2 | Last modified: 2023-02-03 21:04:03 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Removing_the_Account_Requirement_on_Opportunities/index.html |
27a7194ad433-0 | Increasing the Number of Dashboards Displayed in the Home Menu
Overview
By default, the "Home Dashboard" comes out-of-the-box with Sugar® to display on the home page. In addition, Sugar users with a Sugar Serve and/or Sugar Sell license type will have access to specialized Home page dashboards called "Service Console" and "Renewals Console". Users have the ability to create new dashboards on their home page and build out its layout and dashlet set. Currently, Sugar imposes a limit of 50 dashboards that can be displayed under the Home module tab. So, when creating multiple dashboards, keep in mind that having more than 50 in the list of available dashboards will cause the ones in the beginning to be dropped off the list. This article covers how to increase the number of dashboards allowed in the Home menu via a code-level customization.
Use Case
In this example, we will make a code-level change to set the number of dashboards allowed in the Home menu to "80".
Prerequisites
This change requires code-level customizations. You will need direct access to the server as well as administrator access in Sugar in order to perform the necessary actions. If you need assistance making these changes and already have a relationship with a Sugar partner, you can work with them to make this change. If not, please refer to the Partner Page to find a reselling partner to help with your development needs.Â
You will also need the following capabilities prior to making this code-level customization:
You should have a working knowledge of PHP development and arrays.
You should have access to a text editor that can be used for programming. | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Increasing_the_Number_of_Dashboards_Displayed_in_the_Home_Menu/index.html |
27a7194ad433-1 | You should have access to a text editor that can be used for programming.
If your Sugar instance is hosted on Sugar's cloud service or hosted on a server to which you do not have direct file access, you will need to know how to create and deploy Module Loader packages. For more information, please refer to the Module Loader section of the Developer Guide.
Note: Sugar Sell Essentials customers do not have the ability to upload custom file packages to Sugar using Module Loader.
Steps to Complete
The following steps cover setting the number of dashboards allowed on the Home menu to "80" as an example:
Navigate to ./modules/Home/clients/base/views/module-menu/module-menu.php and copy the file contents to a new file at ./custom/modules/Home/clients/base/views/module-menu/module-menu.php. The contents of the file should look similar to this:
<?php
$viewdefs['Home']['base']['view']['module-menu'] = array(
'settings' => array(
'favorites' => 0,
'recently_viewed' => 10,
'recently_viewed_toggle' => 3,
),
);
?>
Modify the ./custom/modules/Home/clients/base/views/module-menu/module-menu.php file and add the dashboards => 80, element to the array. The modified file should look similar to this:<?php
$viewdefs['Home']['base']['view']['module-menu'] = array(
'settings' => array(
'dashboards' => 80,
'favorites' => 0,
'recently_viewed' => 10,
'recently_viewed_toggle' => 3,
),
);
?>
Save the changes to the file and update the ownership and permissions of the files that were created. | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Increasing_the_Number_of_Dashboards_Displayed_in_the_Home_Menu/index.html |
27a7194ad433-2 | Save the changes to the file and update the ownership and permissions of the files that were created.
For more information on Linux-based stacks, please refer to the Required File System Permissions on Linux article.
For more information on Windows-based stacks, please refer to the Required File System Permissions on Windows With IIS article.Â
Finally, log into Sugar as an administrator, navigate to Admin > Repair, and perform a "Quick Repair and Rebuild". This will rebuild the cached files to fully implement the changes to your Sugar instance.
Application
Once the appropriate changes have been made, users should be able to create and view up to 80 dashboards on their home page and any previously missing dashboards should now display in the Home menu as well.
Last modified: 2023-02-03 21:04:03 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Increasing_the_Number_of_Dashboards_Displayed_in_the_Home_Menu/index.html |
ca2a08c148dc-0 | Web Services
Examples when working with Sugar's web service endpoints.
TopicsREST APIExamples of integrating with Sugar REST APIs.Legacy APIExamples of the legacy v4_1 web service endpoints.
Last modified: 2023-02-03 21:04:03 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/index.html |
ea49d88c1983-0 | This API has been succeeded by a new version. It is recommended to upgrade to the latest API.
Legacy API
Examples of the legacy v4_1 web service endpoints.
TopicsRESTExamples of v4.1 REST API calls.SOAPExamples of v4.1 SOAP API calls.
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/index.html |
e6b62967d296-0 | This API has been succeeded by a new version. It is recommended to upgrade to the latest API.
SOAP
Examples of v4.1 SOAP API calls.
TopicsC#C# SOAP v4_1 Examples.
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/SOAP/index.html |
d9fd8e11f88b-0 | This API has been succeeded by a new version. It is recommended to upgrade to the latest API.
C#
C# SOAP v4_1 Examples.
TopicsCreating or Updating a RecordA C# example demonstrating how to create or update an account with the set_entry method using SOAP and the v4 SOAP API.Logging InA C# example demonstrating how to log in and retrieve a session key using SOAP and the v4 SOAP API.
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/SOAP/C_sharp/index.html |
9b263d860132-0 | This API has been succeeded by a new version. It is recommended to upgrade to the latest API.
Creating or Updating a Record
Overview
A C# example demonstrating how to create or update an account with the set_entry method using SOAP and the v4 SOAP API.
Example
using System;
using System.Text;
using System.Security.Cryptography;
using System.Collections.Specialized;
namespace SugarSoap
{
class Program
{
static void Main(string[] args)
{
//login -----------------------------------------
string UserName = "admin";
string Password = "password";
string URL = "http://{site_url}/service/v4/soap.php";
//SugarCRM is a web reference added that points to http://{site_url}/service/v4/soap.php?wsdl
SugarCRM.sugarsoap SugarClient = new SugarCRM.sugarsoap();
SugarClient.Timeout = 900000;
SugarClient.Url = URL;
string SessionID = String.Empty;
//Create authentication object
SugarCRM.user_auth UserAuth = new SugarCRM.user_auth();
//Populate credentials
UserAuth.user_name = UserName;
UserAuth.password = getMD5(Password);
//Try to authenticate
SugarCRM.name_value[] LoginList = new SugarCRM.name_value[0];
SugarCRM.entry_value LoginResult = SugarClient.login(UserAuth, "SoapTest", LoginList);
//get session id
SessionID = LoginResult.id;
//create account --------------------------------
NameValueCollection fieldListCollection = new NameValueCollection();
//to update a record, you will nee to pass in a record id as commented below | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/SOAP/C_sharp/Creating_or_Updating_a_Record/index.html |
9b263d860132-1 | //fieldListCollection.Add("id", "68c4781f-75d1-223a-5d8f-5058bc4e39ea");
fieldListCollection.Add("name", "Test Account");
//this is just a trick to avoid having to manually specify index values for name_value[]
SugarCRM.name_value[] fieldList = new SugarCRM.name_value[fieldListCollection.Count];
int count = 0;
foreach (string name in fieldListCollection)
{
foreach (string value in fieldListCollection.GetValues(name))
{
SugarCRM.name_value field = new SugarCRM.name_value();
field.name = name; field.value = value;
fieldList[count] = field;
}
count++;
}
try
{
SugarCRM.new_set_entry_result result = SugarClient.set_entry(SessionID, "Accounts", fieldList);
string RecordID = result.id;
//show record id to user
Console.WriteLine(RecordID);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.Source);
}
//Pause Window
Console.ReadLine();
}
static private string getMD5(string PlainText)
{
MD5 md5 = MD5.Create();
byte[] inputBuffer = System.Text.Encoding.ASCII.GetBytes(PlainText);
byte[] outputBuffer = md5.ComputeHash(inputBuffer);
//Convert the byte[] to a hex-string
StringBuilder builder = new StringBuilder(outputBuffer.Length);
for (int i = 0; i < outputBuffer.Length; i++)
{
builder.Append(outputBuffer[i].ToString("X2"));
} | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/SOAP/C_sharp/Creating_or_Updating_a_Record/index.html |
9b263d860132-2 | {
builder.Append(outputBuffer[i].ToString("X2"));
}
return Builder.ToString().ToLower(); //lowercase as of 7.9.0.0
}
}
}
Result
68c4781f-75d1-223a-5d8f-5058bc4e39ea
Â
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/SOAP/C_sharp/Creating_or_Updating_a_Record/index.html |
8e9808c06a4e-0 | This API has been succeeded by a new version. It is recommended to upgrade to the latest API.
Logging In
Overview
A C# example demonstrating how to log in and retrieve a session key using SOAP and the v4 SOAP API.
Example
using System;
using System.Text;
using System.Security.Cryptography;
namespace SugarSoap
{
class Program
{
static void Main(string[] args)
{
string UserName = "admin";
string Password = "password";
string URL = "http://{site_url}/service/v4/soap.php";
string SessionID = String.Empty;
//SugarCRM is a web reference added that points to http://{site_url}/service/v4/soap.php?wsdl
SugarCRM.sugarsoap SugarClient = new SugarCRM.sugarsoap();
SugarClient.Timeout = 900000;
SugarClient.Url = URL;
//Create authentication object
SugarCRM.user_auth UserAuth = new SugarCRM.user_auth();
//Populate credentials
UserAuth.user_name = UserName;
UserAuth.password = getMD5(Password);
//Try to authenticate
SugarCRM.name_value[] LoginList = new SugarCRM.name_value[0];
SugarCRM.entry_value LoginResult = SugarClient.login(UserAuth, "SoapTest", LoginList);
//get session id
SessionID = LoginResult.id;
if (SessionID != String.Empty)
{
//print session
Console.WriteLine(SessionID);
}
//Pause Window
Console.ReadLine();
}
static private string getMD5(string TextString)
{
MD5 md5 = MD5.Create();
byte[] inputBuffer = System.Text.Encoding.ASCII.GetBytes(TextString); | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/SOAP/C_sharp/Logging_In/index.html |
8e9808c06a4e-1 | byte[] inputBuffer = System.Text.Encoding.ASCII.GetBytes(TextString);
byte[] outputBuffer = md5.ComputeHash(inputBuffer);
StringBuilder Builder = new StringBuilder(outputBuffer.Length);
for (int i = 0; i < outputBuffer.Length; i++)
{
Builder.Append(outputBuffer[i].ToString("X2"));
}
return Builder.ToString().ToLower(); //lowercase as of 7.9.0.0
}
}
}
Note:Â As of 7.9.0.0, the md5 of the password must be lowercase.
Result
b2uv0vrjfiov41d03sk578ufq6
Â
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/SOAP/C_sharp/Logging_In/index.html |
2a5cbac6d141-0 | This API has been succeeded by a new version. It is recommended to upgrade to the latest API.
REST
Examples of v4.1 REST API calls.
TopicsPHPPHP v4_1 REST Examples.
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/index.html |
321e83995f89-0 | This API has been succeeded by a new version. It is recommended to upgrade to the latest API.
PHP
PHP v4_1 REST Examples. | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/index.html |
321e83995f89-1 | TopicsCreating DocumentsA PHP example demonstrating how to create a document using set_entry and a document revision with the set_document_revision method using cURL and the v4_1 REST API.Creating Notes with AttachmentsA 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.Creating or Updating a RecordA PHP example demonstrating how to create or update an Account with the set_entry method using cURL and the v4_1 REST API.Creating or Updating Multiple RecordsA PHP example demonstrating how to create or update multiple contacts with the set_entries method using cURL and the v4_1 REST API.Creating or Updating TeamsA PHP example demonstrating how to manipulate teams using cURL and the v4_1 REST API.Logging InA PHP example demonstrating how to log in and retrieve a session key using cURL and the v4_1 REST API.Relating Quotes and ProductsA PHP example demonstrating how to create and relate Products to Quotes using cURL and the v4_1 REST API.Retrieving a List of Fields From a ModuleA 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.Retrieving a List of RecordsA 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.Retrieving a List of Records With Related InfoA 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.Retrieving Email AttachmentsA PHP example demonstrating how to retrieve an email and its attachments from using the get_entry and get_note_attachment methods using cURL and the v4_1 REST API.Retrieving Multiple Records by IDA PHP example demonstrating how to retrieve multiple records from the accounts module with the | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/index.html |
321e83995f89-2 | Multiple Records by IDA PHP example demonstrating how to retrieve multiple records from the accounts module with the get_entries method using cURL and the v4_1 REST API.Retrieving Records by Email DomainA PHP example demonstrating how to retrieve email addresses based on an email domain with the search_by_module and get_entries methods using cURL and the v4_1 REST API.Retrieving Related RecordsA PHP example demonstrating how to retrieve a list of related records with the get_relationships method using cURL and the v4_1 REST API.Searching RecordsA PHP example demonstrating how to search the accounts module with the search_by_module method using cURL and the v4_1 REST API. | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/index.html |
321e83995f89-3 | 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/index.html |
1b66c53ca218-0 | This API has been succeeded by a new version. It is recommended to upgrade to the latest API.
Creating or Updating a Record
Overview
A PHP example demonstrating how to create or update an Account with the set_entry 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_or_Updating_a_Record/index.html |
1b66c53ca218-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 account -------------------------------------
$set_entry_parameters = array(
//session id
"session" => $session_id,
//The name of the module from which to retrieve records.
"module_name" => "Accounts",
//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" => "Test Account"),
),
);
$set_entry_result = call("set_entry", $set_entry_parameters, $url);
echo "<pre>";
print_r($set_entry_result);
echo "</pre>";
?>
Result
stdClass Object
(
[id] => 9b170af9-3080-e22b-fbc1-4fea74def88f
[entry_list] => stdClass Object
( | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Creating_or_Updating_a_Record/index.html |
1b66c53ca218-2 | [entry_list] => stdClass Object
(
[name] => stdClass Object
(
[name] => name
[value] => Test Account
)
)
)
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_a_Record/index.html |
50a94f784bd5-0 | This API has been succeeded by a new version. It is recommended to upgrade to the latest API.
Retrieving Email Attachments
Overview
A PHP example demonstrating how to retrieve an email and its attachments from using the get_entry and get_note_attachment methods using cURL and the v4_1 REST API.
This example will retrieve a specified email record by its ID and write the attachments to the local filesystem.
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_Email_Attachments/index.html |
50a94f784bd5-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 the email ---------------------------------------------
// email id of an email with an attachment
$email_id = '5826bd75-527a-a736-edf5-5205421467bf';
// use get_entry to get the email contents
$get_entry_parameters = array(
'session' => $session_id,
'module_name' => 'Emails',
'id' => $email_id,
'select_fields' => array(),
'link_name_to_fields_array' => array(
array(
'name' => 'notes',
'value' => array(
'id',
'name',
'file_mime_type',
'filename',
'description',
),
),
),
'track_view' => false
);
$get_entry_result = call('get_entry', $get_entry_parameters, $url);
//Email record contents
echo "<pre>";
print_r($get_entry_result);
echo "</pre>";
if (!isset($get_entry_result->entry_list[0]))
{
echo "Email not found!";
die();
} | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_Email_Attachments/index.html |
50a94f784bd5-2 | {
echo "Email not found!";
die();
}
if (!isset($get_entry_result->relationship_list) || count($get_entry_result->relationship_list) == 0)
{
echo "No attachments found!";
die();
}
//retrieve any attachments ---------------------------------------------
foreach ($get_entry_result->relationship_list[0][0]->records as $key => $attachmentInfo)
{
$get_note_attachment_parameters = array(
'session' => $session_id,
'id' => $attachmentInfo->id->value,
);
$get_note_attachment_result = call('get_note_attachment', $get_note_attachment_parameters, $url);
//attachment contents
echo "<pre>";
print_r($get_note_attachment_result);
echo "</pre>";
$file_name = $get_note_attachment_result->note_attachment->filename;
//decode and get file contents
$file_contents = base64_decode($get_note_attachment_result->note_attachment->file);
//write file
file_put_contents($file_name, $file_contents);
}
Result
//Email Result
stdClass Object
(
[entry_list] => Array
(
[0] => stdClass Object
(
[id] => 5826bd75-527a-a736-edf5-5205421467bf
[module_name] => Emails
[name_value_list] => stdClass Object
(
[assigned_user_name] => stdClass Object
(
[name] => assigned_user_name
[value] => Administrator
)
[modified_by_name] => stdClass Object
(
[name] => modified_by_name
[value] => Administrator
)
[created_by_name] => stdClass Object | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_Email_Attachments/index.html |
50a94f784bd5-3 | [value] => Administrator
)
[created_by_name] => stdClass Object
(
[name] => created_by_name
[value] => Administrator
)
[team_id] => stdClass Object
(
[name] => team_id
[value] => 1
)
[team_set_id] => stdClass Object
(
[name] => team_set_id
[value] => 1
)
[team_name] => stdClass Object
(
[name] => team_name
[value] => Global
)
[id] => stdClass Object
(
[name] => id
[value] => 5826bd75-527a-a736-edf5-5205421467bf
)
[date_entered] => stdClass Object
(
[name] => date_entered
[value] => 2013-08-09 19:28:00
)
[date_modified] => stdClass Object
(
[name] => date_modified
[value] => 2013-08-09 19:29:08
)
[assigned_user_id] => stdClass Object
(
[name] => assigned_user_id
[value] => 1
)
[modified_user_id] => stdClass Object
(
[name] => modified_user_id
[value] => 1
)
[created_by] => stdClass Object
(
[name] => created_by
[value] => 1
)
[deleted] => stdClass Object
(
[name] => deleted
[value] => 0
) | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_Email_Attachments/index.html |
50a94f784bd5-4 | [name] => deleted
[value] => 0
)
[from_addr_name] => stdClass Object
(
[name] => from_addr_name
[value] => SugarCRM
)
[to_addrs_names] => stdClass Object
(
[name] => to_addrs_names
[value] => email@address.com
)
[description_html] => stdClass Object
(
[name] => description_html
[value] =>
)
[description] => stdClass Object
(
[name] => description
[value] =>
)
[date_sent] => stdClass Object
(
[name] => date_sent
[value] => 2013-08-09 19:28:00
)
[message_id] => stdClass Object
(
[name] => message_id
[value] =>
)
[message_uid] => stdClass Object
(
[name] => message_uid
[value] =>
)
[name] => stdClass Object
(
[name] => name
[value] => Example
)
[type] => stdClass Object
(
[name] => type
[value] => out
)
[status] => stdClass Object
(
[name] => status
[value] => read
)
[flagged] => stdClass Object
(
[name] => flagged
[value] => 0
)
[reply_to_status] => stdClass Object
(
[name] => reply_to_status
[value] => 0
)
[intent] => stdClass Object | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_Email_Attachments/index.html |
50a94f784bd5-5 | [value] => 0
)
[intent] => stdClass Object
(
[name] => intent
[value] => pick
)
[mailbox_id] => stdClass Object
(
[name] => mailbox_id
[value] =>
)
[parent_name] => stdClass Object
(
[name] => parent_name
[value] => Having trouble adding new items
)
[parent_type] => stdClass Object
(
[name] => parent_type
[value] => Cases
)
[parent_id] => stdClass Object
(
[name] => parent_id
[value] => 116d4d46-928c-d4af-c22e-518ae4eb13fc
)
)
)
)
[relationship_list] => Array
(
[0] => Array
(
[0] => stdClass Object
(
[name] => notes
[records] => Array
(
[0] => stdClass Object
(
[id] => stdClass Object
(
[name] => id
[value] => 1b63a8f9-ce67-6aad-b5a4-52054af18c47
)
[name] => stdClass Object
(
[name] => name
[value] => Example.zip
)
[file_mime_type] => stdClass Object
(
[name] => file_mime_type
[value] => application/zip
)
[filename] => stdClass Object
(
[name] => filename
[value] => Example2.zip
) | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_Email_Attachments/index.html |
50a94f784bd5-6 | [name] => filename
[value] => Example2.zip
)
[description] => stdClass Object
(
[name] => description
[value] =>
)
[_empty_] => stdClass Object
(
[name] =>
[value] =>
)
)
[1] => stdClass Object
(
[id] => stdClass Object
(
[name] => id
[value] => 592f382d-b633-fd5f-803e-5205423a6d0b
)
[name] => stdClass Object
(
[name] => name
[value] => Example2.zip
)
[file_mime_type] => stdClass Object
(
[name] => file_mime_type
[value] => application/zip
)
[filename] => stdClass Object
(
[name] => filename
[value] => Example2.zip
)
[description] => stdClass Object
(
[name] => description
[value] =>
)
[_empty_] => stdClass Object
(
[name] =>
[value] =>
)
)
)
)
)
)
)
//Attachment 1 Result
stdClass Object
(
[note_attachment] => stdClass Object
(
[id] => 1b63a8f9-ce67-6aad-b5a4-52054af18c47
[filename] => Example.zip
[file] => UEsDBAoAAAAIAOujCEOkMbvsNa0AAMCFAgAXAAAARmlsZXMvaW | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_Email_Attachments/index.html |
50a94f784bd5-7 | [related_module_id] => 5826bd75-527a-a736-edf5-5205421467bf
[related_module_name] => Emails
)
)
//Attachment 2 Result
stdClass Object
(
[note_attachment] => stdClass Object
(
[id] => 592f382d-b633-fd5f-803e-5205423a6d0b
[filename] => Example2.zip
[file] => AEUoaAAARmlslsZXMvaWZXujCEOkMbvsNa0AAMCFAgAXAAAARm
[related_module_id] => 5826bd75-527a-a736-edf5-5205421467bf
[related_module_name] => Emails
)
)
Related
Â
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_Email_Attachments/index.html |
0cf03a55563e-0 | This API has been succeeded by a new version. It is recommended to upgrade to the latest API.
Creating Documents
Overview
A PHP example demonstrating how to create a document using set_entry and a document revision with the set_document_revision 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_Documents/index.html |
0cf03a55563e-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 document --------------------------------------------
$set_entry_parameters = array(
//session id
"session" => $session_id,
//The name of the module
"module_name" => "Documents",
//Record attributes
"name_value_list" => array(
//to update a record, pass in a record id as commented below
//array("name" => "id", "value" => "9b170af9-3080-e22b-fbc1-4fea74def88f"),
array("name" => "document_name", "value" => "Example Document"),
array("name" => "revision", "value" => "1"),
),
);
$set_entry_result = call("set_entry", $set_entry_parameters, $url);
echo "<pre>";
print_r($set_entry_result);
echo "</pre>";
$document_id = $set_entry_result->id;
//create document revision ------------------------------------
$contents = file_get_contents ("/path/to/example_document.txt");
$set_document_revision_parameters = array( | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Creating_Documents/index.html |
0cf03a55563e-2 | $set_document_revision_parameters = array(
//session id
"session" => $session_id,
//The attachment details
"note" => array(
//The ID of the parent document.
'id' => $document_id,
//The binary contents of the file.
'file' => base64_encode($contents),
//The name of the file
'filename' => 'example_document.txt',
//The revision number
'revision' => '1',
),
);
$set_document_revision_result = call("set_document_revision", $set_document_revision_parameters, $url);
echo "<pre>";
print_r($set_document_revision_result);
echo "</pre>";
?>
Result
//set_entry result
stdClass Object
(
[id] => b769cf46-7881-a369-314d-50abaa238c62
[entry_list] => stdClass Object
(
[document_name] => stdClass Object
(
[name] => document_name
[value] => Example Document
)
[revision] => stdClass Object
(
[name] => revision
[value] => 1
)
)
)
//set_document_revision result
stdClass Object
(
[id] => e83f97b9-b818-2d04-1aeb-50abaa8303b5
)
Â
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_Documents/index.html |
9e409287714b-0 | This API has been succeeded by a new version. It is recommended to upgrade to the latest API.
Retrieving Records by Email Domain
Overview
A PHP example demonstrating how to retrieve email addresses based on an email domain with the search_by_module and get_entries methods using cURL and the v4_1 REST API.
When using the search_by_module method, the email address information is not returned in the result. Due to this behavior, we will gather the record ids and pass them back to the get_entries method to fetch our 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); | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_Records_by_Email_Domain/index.html |
9e409287714b-1 | $result = curl_exec($curl_request);
curl_close($curl_request);
$result = explode("\r\n\r\n", $result, 2);
$response = json_decode($result[1]);
ob_end_flush();
return $response;
}
//login --------------------------------------------
$login_parameters = array(
"user_auth" => array(
"user_name" => $username,
"password" => md5($password),
"version" => "1"
),
"application_name" => "RestTest",
"name_value_list" => array(),
);
$login_result = call("login", $login_parameters, $url);
/*
echo "<pre>";
print_r($login_result);
echo "</pre>";
*/
//get session id
$session_id = $login_result->id;
//search_by_module -------------------------------------------------
$search_by_module_parameters = array(
"session" => $session_id,
'search_string' => '%@example.com',
'modules' => array(
'Accounts',
'Contacts',
'Leads',
),
'offset' => 0,
'max_results' => 1,
'assigned_user_id' => '',
'select_fields' => array('id'),
'unified_search_only' => false,
'favorites' => false
);
$search_by_module_results = call('search_by_module', $search_by_module_parameters, $url);
/*
echo '<pre>';
print_r($search_by_module_results); | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_Records_by_Email_Domain/index.html |
9e409287714b-2 | /*
echo '<pre>';
print_r($search_by_module_results);
echo '</pre>';
*/
$record_ids = array();
foreach ($search_by_module_results->entry_list as $results)
{
$module = $results->name;
foreach ($results->records as $records)
{
foreach($records as $record)
{
if ($record->name = 'id')
{
$record_ids[$module][] = $record->value;
//skip any additional fields
break;
}
}
}
}
$get_entries_results = array();
$modules = array_keys($record_ids);
foreach($modules as $module)
{
$get_entries_parameters = array(
//session id
'session' => $session_id,
//The name of the module from which to retrieve records
'module_name' => $module,
//An array of record IDs
'ids' => $record_ids[$module],
//The list of fields to be returned in the results
'select_fields' => array(
'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(
'email_address',
'opt_out',
'primary_address'
),
),
),
//Flag the record as a recently viewed item
'track_view' => false,
); | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_Records_by_Email_Domain/index.html |
9e409287714b-3 | 'track_view' => false,
);
$get_entries_results[$module] = call('get_entries', $get_entries_parameters, $url);
}
echo '<pre>';
print_r($get_entries_results);
echo '</pre>';
Result
Array
(
[Accounts] => stdClass Object
(
[entry_list] => Array
(
[0] => stdClass Object
(
[id] => 1bb7ef28-64b9-cbd5-e7d6-5282a3b96953
[module_name] => Accounts
[name_value_list] => stdClass Object
(
[name] => stdClass Object
(
[name] => name
[value] => Underwater Mining Inc.
)
)
)
[1] => stdClass Object
(
[id] => efbc0c4e-cc72-f843-b6ed-5282a38dad7f
[module_name] => Accounts
[name_value_list] => stdClass Object
(
[name] => stdClass Object
(
[name] => name
[value] => 360 Vacations
)
)
)
)
[relationship_list] => Array
(
[0] => stdClass Object
(
[link_list] => Array
(
[0] => stdClass Object
(
[name] => email_addresses
[records] => Array
(
[0] => stdClass Object
(
[link_value] => stdClass Object
(
[email_address] => stdClass Object
(
[name] => email_address | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_Records_by_Email_Domain/index.html |
9e409287714b-4 | [email_address] => stdClass Object
(
[name] => email_address
[value] => beans.the.qa@example.com
)
[opt_out] => stdClass Object
(
[name] => opt_out
[value] => 0
)
[primary_address] => stdClass Object
(
[name] => primary_address
[value] =>
)
)
)
[1] => stdClass Object
(
[link_value] => stdClass Object
(
[email_address] => stdClass Object
(
[name] => email_address
[value] => section.sales@example.edu
)
[opt_out] => stdClass Object
(
[name] => opt_out
[value] => 0
)
[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
(
[email_address] => stdClass Object
(
[name] => email_address
[value] => section51@example.com
)
[opt_out] => stdClass Object
(
[name] => opt_out
[value] => 0
)
[primary_address] => stdClass Object
(
[name] => primary_address
[value] => | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_Records_by_Email_Domain/index.html |
9e409287714b-5 | (
[name] => primary_address
[value] =>
)
)
)
[1] => stdClass Object
(
[link_value] => stdClass Object
(
[email_address] => stdClass Object
(
[name] => email_address
[value] => kid.sugar.qa@example.co.uk
)
[opt_out] => stdClass Object
(
[name] => opt_out
[value] => 0
)
[primary_address] => stdClass Object
(
[name] => primary_address
[value] =>
)
)
)
)
)
)
)
)
)
[Contacts] => stdClass Object
(
[entry_list] => Array
(
[0] => stdClass Object
(
[id] => 24330979-0e39-f9ec-2622-5282a372f39b
[module_name] => Contacts
[name_value_list] => stdClass Object
(
[name] => stdClass Object
(
[name] => name
[value] => Errol Goldberg
)
)
)
[1] => stdClass Object
(
[id] => 2542dad2-85f3-5529-3a30-5282a3104e31
[module_name] => Contacts
[name_value_list] => stdClass Object
(
[name] => stdClass Object
(
[name] => name
[value] => Luis Deegan
)
)
)
)
[relationship_list] => Array
( | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_Records_by_Email_Domain/index.html |
9e409287714b-6 | )
)
)
[relationship_list] => Array
(
[0] => stdClass Object
(
[link_list] => Array
(
[0] => stdClass Object
(
[name] => email_addresses
[records] => Array
(
[0] => stdClass Object
(
[link_value] => stdClass Object
(
[email_address] => stdClass Object
(
[name] => email_address
[value] => hr.phone@example.com
)
[opt_out] => stdClass Object
(
[name] => opt_out
[value] => 0
)
[primary_address] => stdClass Object
(
[name] => primary_address
[value] =>
)
)
)
[1] => stdClass Object
(
[link_value] => stdClass Object
(
[email_address] => stdClass Object
(
[name] => email_address
[value] => the.info.phone@example.cn
)
[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 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_Records_by_Email_Domain/index.html |
9e409287714b-7 | [0] => stdClass Object
(
[link_value] => stdClass Object
(
[email_address] => stdClass Object
(
[name] => email_address
[value] => im.the.sales@example.name
)
[opt_out] => stdClass Object
(
[name] => opt_out
[value] => 0
)
[primary_address] => stdClass Object
(
[name] => primary_address
[value] =>
)
)
)
[1] => stdClass Object
(
[link_value] => stdClass Object
(
[email_address] => stdClass Object
(
[name] => email_address
[value] => the36@example.com
)
[opt_out] => stdClass Object
(
[name] => opt_out
[value] => 1
)
[primary_address] => stdClass Object
(
[name] => primary_address
[value] =>
)
)
)
)
)
)
)
)
)
[Leads] => stdClass Object
(
[entry_list] => Array
(
[0] => stdClass Object
(
[id] => 83abeeff-5e71-0f06-2e5f-5282a3f04f41
[module_name] => Leads
[name_value_list] => stdClass Object
(
[name] => stdClass Object
(
[name] => name
[value] => Caryn Wert
)
)
)
[1] => stdClass Object
( | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_Records_by_Email_Domain/index.html |
9e409287714b-8 | )
)
)
[1] => stdClass Object
(
[id] => 2a3b304b-5167-8432-d4e7-5282a300eabb
[module_name] => Leads
[name_value_list] => stdClass Object
(
[name] => stdClass Object
(
[name] => name
[value] => Marco Castonguay
)
)
)
)
[relationship_list] => Array
(
[0] => stdClass Object
(
[link_list] => Array
(
[0] => stdClass Object
(
[name] => email_addresses
[records] => Array
(
[0] => stdClass Object
(
[link_value] => stdClass Object
(
[email_address] => stdClass Object
(
[name] => email_address
[value] => hr60@example.com
)
[opt_out] => stdClass Object
(
[name] => opt_out
[value] => 0
)
[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
(
[email_address] => stdClass Object
( | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_Records_by_Email_Domain/index.html |
9e409287714b-9 | (
[email_address] => stdClass Object
(
[name] => email_address
[value] => im.the@example.com
)
[opt_out] => stdClass Object
(
[name] => opt_out
[value] => 0
)
[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_Records_by_Email_Domain/index.html |
2a13cf8254a7-0 | This API has been succeeded by a new version. It is recommended to upgrade to the latest API.
Retrieving Multiple Records by ID
Overview
A PHP example demonstrating how to retrieve multiple records from the accounts module with the get_entries method using cURL and the v4_1 REST API.
This example will only retrieve 2 records and return the following fields: 'name', 'billing_address_state' and 'billing_address_country'.
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/Retrieving_Multiple_Records_by_ID/index.html |
2a13cf8254a7-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;
//retrieve records -----------------------------------
$get_entries_parameters = array(
//session id
'session' => $session_id,
//The name of the module from which to retrieve records
'module_name' => 'Accounts',
//An array of SugarBean IDs
'ids' => array(
'20328809-9d0a-56fc-0e7c-4f7cb6eb1c83',
'328b22a6-d784-66d9-0295-4f7cb59e8cbb',
),
//Optional. The list of fields to be returned in the results
'select_fields' => array(
'name',
'billing_address_state',
'billing_address_country'
),
//A list of link names and the fields to be returned for each link name
'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_Multiple_Records_by_ID/index.html |
2a13cf8254a7-2 | 'link_name_to_fields_array' => array(
),
);
$get_entries_result = call("get_entries", $get_entries_parameters, $url);
echo "<pre>";
print_r($get_entries_result);
echo "</pre>";
?>
Result
stdClass Object
(
[entry_list] => Array
(
[0] => stdClass Object
(
[id] => 20328809-9d0a-56fc-0e7c-4f7cb6eb1c83
[module_name] => Accounts
[name_value_list] => stdClass Object
(
[name] => stdClass Object
(
[name] => name
[value] => Jungle Systems Inc
)
[billing_address_state] => stdClass Object
(
[name] => billing_address_state
[value] => NY
)
[billing_address_country] => stdClass Object
(
[name] => billing_address_country
[value] => USA
)
)
)
[1] => stdClass Object
(
[id] => 328b22a6-d784-66d9-0295-4f7cb59e8cbb
[module_name] => Accounts
[name_value_list] => stdClass Object
(
[name] => stdClass Object
(
[name] => name
[value] => Riviera Hotels
)
[billing_address_state] => stdClass Object
(
[name] => billing_address_state
[value] => CA
)
[billing_address_country] => stdClass Object
(
[name] => billing_address_country
[value] => USA | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Retrieving_Multiple_Records_by_ID/index.html |
2a13cf8254a7-3 | (
[name] => billing_address_country
[value] => USA
)
)
)
)
[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_Multiple_Records_by_ID/index.html |
e53873ca382a-0 | This API has been succeeded by a new version. It is recommended to upgrade to the latest API.
Relating Quotes and Products
Overview
A PHP example demonstrating how to create and relate Products to Quotes 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 ----------------------------------------------
$login_parameters = array( | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Relating_Quotes_and_Products/index.html |
e53873ca382a-1 | }
//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 quote ----------------------------------------------
$createQuoteParams = array(
'session' => $session_id,
'module_name' => 'Quotes',
'name_value_list' => array(
array(
'name' => 'name',
'value' => 'Widget Quote'
),
array(
'name' => 'team_count',
'value' => ''
),
array(
'name' => 'team_name',
'value' => ''
),
array(
'name' => 'date_quote_expected_closed',
'value' => date('Y-m-d', mktime(0, 0, 0, date('m') , date('d')+7, date('Y')))
),
array(
'name' => 'quote_stage',
'value' => 'Negotiation'
),
array(
'name' => 'quote_num',
'value' => ''
),
array(
'name' => 'quote_type',
'value' => 'Quotes' | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Relating_Quotes_and_Products/index.html |
e53873ca382a-2 | 'name' => 'quote_type',
'value' => 'Quotes'
),
array(
'name' => 'subtotal',
'value' => '1230.23'
),
array(
'name' => 'subtotal_usdollar',
'value' => '1230.23'
),
),
);
$createQuoteResult = call('set_entry', $createQuoteParams, $url);
echo "Create Quote Result<br />";
echo "<pre>";
print_r($createQuoteResult);
echo "</pre>";
//create product ----------------------------------------------
$createProductParams = array(
'session' => $session_id,
'module_name' => 'Products',
'name_value_list' => array(
array(
'name' => 'name',
'value' => 'Widget'
),
array(
'name' => 'quote_id',
'value' => $createQuoteResult->id
),
array(
'name' => 'status',
'value' => 'Quotes'
)
)
);
$createProductResult = call('set_entry', $createProductParams, $url);
echo "Create Product Result<br />";
echo "<pre>";
print_r($createProductResult);
echo "</pre>";
//create product-bundle ----------------------------------------------
$createProductBundleParams = array(
"session" => $session_id,
"module_name" => "ProductBundles",
"name_value_list" => array(
array(
'name' => 'name',
'value' => 'Rest SugarOnline Order'), | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Relating_Quotes_and_Products/index.html |
e53873ca382a-3 | 'value' => 'Rest SugarOnline Order'),
array(
'name' => 'bundle_stage',
'value' => 'Draft'
),
array(
'name' => 'tax',
'value' => '0.00'
),
array(
'name' => 'total',
'value' => '0.00'
),
array(
'name' => 'subtotal',
'value' => '0.00'
),
array(
'name' => 'shippint',
'value' => '0.00'
),
array(
'name' => 'currency_id',
'value' => '-99'
),
)
);
$createProductBundleResult = call('set_entry', $createProductBundleParams, $url);
echo "Create ProductBundles Result<br />";
echo "<pre>";
print_r($createProductBundleResult);
echo "</pre>";
//relate product to product-bundle ----------------------------------------
$relationshipProductBundleProductsParams = array(
'sesssion' => $session_id,
'module_name' => 'ProductBundles',
'module_id' => $createProductBundleResult->id,
'link_field_name' => 'products',
'related_ids' => array(
$createProductResult->id
),
);
// set the product bundles products relationship
$relationshipProductBundleProductResult = call('set_relationship', $relationshipProductBundleProductsParams, $url);
echo "Create ProductBundleProduct Relationship Result<br />";
echo "<pre>";
print_r($relationshipProductBundleProductResult); | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Relating_Quotes_and_Products/index.html |
e53873ca382a-4 | echo "<pre>";
print_r($relationshipProductBundleProductResult);
echo "</pre>";
//relate product-bundle to quote ----------------------------------------
$relationshipProductBundleQuoteParams = array(
'sesssion' => $session_id,
'module_name' => 'Quotes',
'module_id' => $createQuoteResult->id,
'link_field_name' => 'product_bundles',
'related_ids' => array(
$createProductBundleResult->id
),
'name_value_list' => array()
);
// set the product bundles quotes relationship
$relationshipProductBundleQuoteResult = call('set_relationship', $relationshipProductBundleQuoteParams, $url);
echo "Create ProductBundleQuote Relationship Result<br />";
echo "<pre>";
print_r($relationshipProductBundleQuoteResult);
echo "</pre>";
Result
//Create Quote Result
stdClass Object
(
[id] => 2e0cd18b-21da-50f0-10f6-517e835a1e09
[entry_list] => stdClass Object
(
[name] => stdClass Object
(
[name] => name
[value] => Widget Quote
)
[team_count] => stdClass Object
(
[name] => team_count
[value] =>
)
[team_name] => stdClass Object
(
[name] => team_name
[value] =>
)
[date_quote_expected_closed] => stdClass Object
(
[name] => date_quote_expected_closed
[value] => 2013-05-06
)
[quote_stage] => stdClass Object
( | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Relating_Quotes_and_Products/index.html |
e53873ca382a-5 | )
[quote_stage] => stdClass Object
(
[name] => quote_stage
[value] => Negotiation
)
[quote_num] => stdClass Object
(
[name] => quote_num
[value] =>
)
[quote_type] => stdClass Object
(
[name] => quote_type
[value] => Quotes
)
[subtotal] => stdClass Object
(
[name] => subtotal
[value] => 1230.23
)
[subtotal_usdollar] => stdClass Object
(
[name] => subtotal_usdollar
[value] => 1230.23
)
)
)
//Create Product Result
stdClass Object
(
[id] => 6c40f344-a269-d4d0-9929-517e83884fb2
[entry_list] => stdClass Object
(
[name] => stdClass Object
(
[name] => name
[value] => Widget
)
[quote_id] => stdClass Object
(
[name] => quote_id
[value] => 2e0cd18b-21da-50f0-10f6-517e835a1e09
)
[status] => stdClass Object
(
[name] => status
[value] => Quotes
)
)
)
//Create ProductBundles Result
stdClass Object
(
[id] => a8a4e449-7e72-dea5-9495-517e830a7353
[entry_list] => stdClass Object
(
[name] => stdClass Object
( | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Relating_Quotes_and_Products/index.html |
e53873ca382a-6 | (
[name] => stdClass Object
(
[name] => name
[value] => Rest SugarOnline Order
)
[bundle_stage] => stdClass Object
(
[name] => bundle_stage
[value] => Draft
)
[tax] => stdClass Object
(
[name] => tax
[value] => 0
)
[total] => stdClass Object
(
[name] => total
[value] => 0
)
[subtotal] => stdClass Object
(
[name] => subtotal
[value] => 0
)
[currency_id] => stdClass Object
(
[name] => currency_id
[value] => -99
)
)
)
//Create ProductBundleProduct Relationship Result
stdClass Object
(
[created] => 1
[failed] => 0
[deleted] => 0
)
//Create ProductBundleQuote Relationship Result
stdClass Object
(
[created] => 1
[failed] => 0
[deleted] => 0
)
Â
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/Relating_Quotes_and_Products/index.html |
077918f078ce-0 | This API has been succeeded by a new version. It is recommended to upgrade to the latest API.
Creating or Updating Multiple Records
Overview
A PHP example demonstrating how to create or update multiple contacts with the set_entries 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 --------------------------------------------
$login_parameters = array( | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Creating_or_Updating_Multiple_Records/index.html |
077918f078ce-1 | }
//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 contacts ------------------------------------
$set_entries_parameters = array(
//session id
"session" => $session_id,
//The name of the module from which to retrieve records.
"module_name" => "Contacts",
//Record attributes
"name_value_list" => array(
array(
//to update a record, you will nee to pass in a record id as commented below
//array("name" => "id", "value" => "912e58c0-73e9-9cb6-c84e-4ff34d62620e"),
array("name" => "first_name", "value" => "John"),
array("name" => "last_name", "value" => "Smith"),
),
array(
//to update a record, you will nee to pass in a record id as commented below
//array("name" => "id", "value" => "99d6ddfd-7d52-d45b-eba8-4ff34d684964"), | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Creating_or_Updating_Multiple_Records/index.html |
077918f078ce-2 | array("name" => "first_name", "value" => "Jane"),
array("name" => "last_name", "value" => "Doe"),
),
),
);
$set_entries_result = call("set_entries", $set_entries_parameters, $url);
echo "<pre>";
print_r($set_entries_result);
echo "</pre>";
?>
Result
stdClass Object
(
[ids] => Array
(
[0] => 912e58c0-73e9-9cb6-c84e-4ff34d62620e
[1] => 99d6ddfd-7d52-d45b-eba8-4ff34d684964
)
)
Â
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_Multiple_Records/index.html |
3512510b0cd9-0 | This API has been succeeded by a new version. It is recommended to upgrade to the latest API.
Logging In
Overview
A PHP example demonstrating how to log in and retrieve a session key using cURL and the v4_1 REST API.
Standard Authentication 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 ------------------------------
$login_parameters = array( | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Logging_In/index.html |
3512510b0cd9-1 | }
//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;
?>
LDAP Authentication Example
<?php
$url = "http://{site_url}/service/v4_1/rest.php";
$username = "admin";
$password = "password";
$ldap_enc_key = 'LDAP_ENCRYPTION_KEY';
//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", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Logging_In/index.html |
3512510b0cd9-2 | "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 ---------------------------------
$ldap_enc_key = substr(md5($ldap_enc_key), 0, 24);
$login_parameters = array(
"user_auth" => array(
"user_name" => $username,
"password" => bin2hex(mcrypt_encrypt(MCRYPT_3DES, $ldap_enc_key, $password, MCRYPT_MODE_CBC, "password")),
"version" => "1"
),
"application_name" => "RestTest",
"name_value_list" => array(),
);
/*
The mcrypt extension is deprecated as of PHP 7.1.
If on 7.1+, LDAP passwords will need to be sent unencrypted, with
$login_parameters["user_auth"]["encryption"] set to "PLAIN". An example is below:
$login_parameters = array(
"user_auth" => array(
"user_name" => $username,
"password" => $password,
"version" => "1",
"encryption" => "PLAIN"
),
"application_name" => "RestTest",
"name_value_list" => array(),
);
*/
$login_result = call("login", $login_parameters, $url); | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Logging_In/index.html |
3512510b0cd9-3 | */
$login_result = call("login", $login_parameters, $url);
echo "<pre>";
print_r($login_result);
echo "</pre>";
//get session id
$session_id = $login_result->id;
?>
Result
stdClass Object
(
[id] => lb7479svj8pjtf57ipmshepo80
[module_name] => Users
[name_value_list] => stdClass Object
(
[user_id] => stdClass Object
(
[name] => user_id
[value] => 1
)
[user_name] => stdClass Object
(
[name] => user_name
[value] => admin
)
[user_language] => stdClass Object
(
[name] => user_language
[value] => en_us
)
[user_currency_id] => stdClass Object
(
[name] => user_currency_id
[value] => -99
)
[user_is_admin] => stdClass Object
(
[name] => user_is_admin
[value] => 1
)
[user_default_team_id] => stdClass Object
(
[name] => user_default_team_id
[value] => 1
)
[user_default_dateformat] => stdClass Object
(
[name] => user_default_dateformat
[value] => m/d/Y
)
[user_default_timeformat] => stdClass Object
(
[name] => user_default_timeformat
[value] => h:ia
)
[user_number_seperator] => stdClass Object
(
[name] => user_number_seperator | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/Legacy_API/REST/PHP/Logging_In/index.html |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.