processfast / yii2-suitecrm-rest-api-client
SuiteCRM / SugarCRM 6.x REST API Wrapper Class
Installs: 8 898
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 4
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- php: >=5.6.19 <7.5
- yiisoft/yii2-httpclient: <=2.0.4
This package is auto-updated.
Last update: 2025-03-07 04:22:28 UTC
README
This extension provides the AWS SDK 3 integration for the Yii2 framework
Contents
- About
- Installation
- Yii2 Configuration
- Usage Example
- Notes
- get_note_attachment() Example
- set_note_attachment() Example
1.About
- PHP wrapper class for interacting with a SugarCRM REST API
- Creating, reading, and updating capability
- More info on SuiteCRM: https://suitecrm.com/
- More info on SugarCRM: http://www.sugarcrm.com/
- API docs: http://developers.sugarcrm.com/
- Designed to work with SuiteCRM / SugarCRM v.6
2.Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist processfast/yii2-suitecrm-rest-api-client "*"
or add
"processfast/yii2-suitecrm-rest-api-client": "*"
to the require section of your composer.json
file.
3.Yii2 Configuration
To use this extension, simply add the following code in your application configuration:
return [ //.... 'components' => [ 'suitecrm' => [ 'class' => 'processfast\suitecrm\SuiteCrmRestApi', 'rest_url' => 'https://mysuitecrm.com/service/v2/rest.php', 'username' => 'your-crm-username', 'password' => 'your-crm-password' ], ], ];
4.Usage Example
Example Snippet:
$suiteCrm = Yii::$app->suitecrm; $suiteCrm->connect(); $error = $suiteCrm->get_error(); if($error !== FALSE) { return $error['name']; } $results = $suiteCrm->get_with_related("Accounts", array("Accounts" => array('id','name'), "Cases" => array('id','status'))); $suiteCrm->print_results($results);
5.Notes
- The
is_valid_id()
function may need to modify for different versions of SugarCRM. - Different versions of SugarCRM have different ID formats.
6.get_note_attachment() Example
This example outputs the contents of a note's attachment, given the note ID. Assumes $note_id contains the ID of the note you wish to modify.
$suiteCrm = Yii::$app->suitecrm;
$suiteCrm->connect();
$result = $suiteCrm->get_note_attachment($note_id);
$filename = $result['note_attachment']['filename'];
$file = $result['note_attachment']['file'];
$file = base64_decode($file);
header("Cache-Control: no-cache private");
header("Content-Description: File Transfer");
header('Content-disposition: attachment; filename='.$filename);
header("Content-Type: application/vnd.ms-excel");
header("Content-Transfer-Encoding: binary");
header('Content-Length: '. strlen($file));
echo $file;
exit;
6.set_note_attachment() Example
This example illustrates how to set a note's attachment from an html form. Assumes $note_id contains the ID of the note you wish to modify.
HTML Code
<form method="post" action="example.php" enctype="multipart/form-data">
<input name="note_file" type="file" />
<input type="submit" value="Go" />
</form>
PHP Code (example.php)
$suiteCrm = Yii::$app->suitecrm;
$suiteCrm->connect();
if ($_FILES["note_file"]["error"] > 0) {
// Error: $_FILES["file"]["error"]
} else if(isset($_FILES['note_file']['tmp_name']) && $_FILES['note_file']['tmp_name']!="") {
$handle = fopen($_FILES['note_file']['tmp_name'], "rb");
$filename = $_FILES['note_file']['name'];
$contents = fread($handle, filesize($_FILES['note_file']['tmp_name']));
$binary = base64_encode($contents);
$file_results = $sugar->set_note_attachment($note_id,$binary,$filename);
}
7.get_available_modules() Example
This example illustrates how to get the available modules in SuiteCRM/SugarCRM. All of them. This is a handy function to use when building future proof SuiteCRM/SugarCRM plugins.
PHP Code (example.php)
$suiteCrm = Yii::$app->suitecrm;
$modules = $suiteCrm->get_available_modules();
BAM! Now loop through the array that was returned and stored in $modules. You could use this to display a dropdown in the admin panel that displays all modules a user would want to connect your sugarcrm plugin to.