PHP code example of inetprocess / sugarcrm-apiwrapper
1. Go to this page and download the library: Download inetprocess/sugarcrm-apiwrapper library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
inetprocess / sugarcrm-apiwrapper example snippets
netProcess\SugarAPI\BaseRequest;
$url = 'http://127.0.0.1';
$username = 'admin';
$password = 'admin';
$base = new BaseRequest($url);
$base->setUsername($username)->setPassword($password);
// The login can be called dynamically as the class will detect you are not logged
// But to save an API Request, call it manually
$base->login();
// Get the list of Contacts
// '200' is the expected Status Code. If it's not the right one, you'll get an Exception
$data = $base->request('/Contacts', ['OAuth-Token' => $base->getToken()], [], 'get', 200);
$notes = $module->retrieve('Notes', null, 0, 10);
if (!empty($notes['records'])) {
echo $notes['records'][0]['name']; // Displays the name of the note
}
$noteId = '123456-abcdef-78910';
$note = $module->retrieve('Notes', $noteId);
if (!empty($note)) {
echo $note['name']; // Displays the name of the note
}
$data = $module->create('Notes', ['name' => 'Name']);
echo $data['note']; // Displays New Name
$noteId = '123456-abcdef-78910';
$data = $module->update('Notes', $noteId, ['name' => 'New Name']);
echo $data['note']; // Displays New Name