Skip to content

v1.0.0 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ Pull requests are accepted under the discretion of the Sugar PHP Rest Client mai

File bugs or feature requests using Github Issue Tracker.

https://github.com/sugarcrm-developers/php-rest-client/issues
https://github.com/sugarcrm-developers/php-rest-client/issues
6 changes: 3 additions & 3 deletions examples/AuditLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
$Account['name'] = 'Audit Log Test - Updated';
$Account['assigned_user_id'] = 'seed_max_id';
$Account->save();
echo "Account Updated: " . json_encode($Account->toArray(),JSON_PRETTY_PRINT) . "\n";
echo "Account Updated: " . json_encode($Account->toArray(), JSON_PRETTY_PRINT) . "\n";
$Account->audit();
echo "Audit Log: " . json_encode($Account->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
echo "Audit Log: " . json_encode($Account->getResponseBody(), JSON_PRETTY_PRINT) . "\n";
} else {
echo "Could not login.";
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');
Expand All @@ -36,4 +36,4 @@
} catch (Exception $ex) {
echo "Exception Occurred: " . $ex->getMessage();
echo $ex->getTraceAsString();
}
}
4 changes: 2 additions & 2 deletions examples/Bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

try {
if ($SugarAPI->isAuthenticated()) {
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";

$lead1 = $SugarAPI->module("Leads");
$lead2 = $SugarAPI->module("Leads");
Expand Down Expand Up @@ -44,4 +44,4 @@
} catch (Exception $ex) {
echo "Exception Occurred: " . $ex->getMessage();
echo $ex->getTraceAsString();
}
}
8 changes: 4 additions & 4 deletions examples/CRUD.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

try {
if ($SugarAPI->isAuthenticated()) {
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";
// Create an Account called Test with a phone number
$Account = $SugarAPI->module('Accounts');
// You can set data via Array Access, Object Access, or set methods
Expand All @@ -24,15 +24,15 @@
$Account->set('employees', '100');
$Account['shipping_address_city'] = 'Indianapolis';
$Account->save();
echo "Account Updated: " . json_encode($Account->toArray(),JSON_PRETTY_PRINT) . "\n";
echo "Account Updated: " . json_encode($Account->toArray(), JSON_PRETTY_PRINT) . "\n";

//Retrieve the Account in a new Object
$Account2 = $SugarAPI->module('Accounts', $Account['id']);
$Account2->retrieve();
echo "Retrieved Account: " . json_encode($Account2->toArray(),JSON_PRETTY_PRINT) . "\n";
echo "Retrieved Account: " . json_encode($Account2->toArray(), JSON_PRETTY_PRINT) . "\n";
//Delete the Account
$Account2->delete();
echo "Deleted Response: " . json_encode($Account2->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
echo "Deleted Response: " . json_encode($Account2->getResponseBody(), JSON_PRETTY_PRINT) . "\n";
} else {
echo "Could not login.";
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');
Expand Down
4 changes: 2 additions & 2 deletions examples/DuplicateCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

try {
if ($SugarAPI->isAuthenticated()) {
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";
//Create a new Account
$Account = $SugarAPI->module('Accounts')->set("name", "DuplicateCheck Test");
$Account->save();
echo "Account Created: {$Account['id']}\n";
// Run duplicate check
$Account->duplicateCheck();
echo "Response: " . json_encode($Account->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
echo "Response: " . json_encode($Account->getResponseBody(), JSON_PRETTY_PRINT) . "\n";
} else {
echo "Could not login.";
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');
Expand Down
4 changes: 2 additions & 2 deletions examples/Favorite.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

try {
if ($SugarAPI->isAuthenticated()) {
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";
//Create a new Account
$Account = $SugarAPI->module('Accounts')->set("name", "Favorite Test");
$Account->save();
Expand All @@ -29,4 +29,4 @@
} catch (Exception $ex) {
echo "Exception Occurred: " . $ex->getMessage();
echo $ex->getTraceAsString();
}
}
6 changes: 3 additions & 3 deletions examples/FileManipulation.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@
$SugarAPI = new \Sugarcrm\REST\Client\SugarAPI($server, $credentials);
try {
if ($SugarAPI->isAuthenticated()) {
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";

$Note = $SugarAPI->module('Notes')->set("name", "Test");
//Create a note with subject
$Note->save();
echo "Saved Note ID: {$Note['id']}<br>";
echo "Attempting to attach $file...";
$Note->attachFile('filename', $file, true, 'testtest.txt');
echo "File uploaded: " . json_encode($Note->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
echo "File uploaded: " . json_encode($Note->getResponseBody(), JSON_PRETTY_PRINT) . "\n";

$Note = $SugarAPI->module('Notes');
echo "Uploading temp file for new note...";
$Note->tempFile('filename', $file);
echo "Temp File uploaded: " . json_encode($Note->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
echo "Temp File uploaded: " . json_encode($Note->getResponseBody(), JSON_PRETTY_PRINT) . "\n";
$Note->set('name', 'This is a test');
$Note->save();
echo "Note ID: {$Note['id']}\n";
Expand Down
4 changes: 2 additions & 2 deletions examples/FilterAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
$SugarAPI = new \Sugarcrm\REST\Client\SugarApi($server, $credentials);
try {
if ($SugarAPI->isAuthenticated()) {
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";

$Accounts = $SugarAPI->list('Accounts');
$Accounts->filter()->and()
Expand Down Expand Up @@ -40,7 +40,7 @@
->endDate()
->endOr();
echo "Filtering Accounts that are created between dates, or in the last 7 days: "
. json_encode($Accounts->filter()->compile(),JSON_PRETTY_PRINT) . "\n";
. json_encode($Accounts->filter()->compile(), JSON_PRETTY_PRINT) . "\n";
$Accounts->fetch();
echo "Accounts: " . json_encode($Accounts->toArray(), JSON_PRETTY_PRINT) . "\n";
} else {
Expand Down
8 changes: 4 additions & 4 deletions examples/FilterRelated.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
$SugarAPI = new \Sugarcrm\REST\Client\SugarApi($server, $credentials);
try {
if ($SugarAPI->isAuthenticated()) {
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";
$Accounts = $SugarAPI->list('Accounts');
$Accounts->fetch();
//Get first Account in Collection
$Account = $Accounts->at(1);
//Execute Related contacts count API call
$Account->getRelated('contacts', true);
echo "Related Contacts Count response: " . json_encode($Account->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
echo "Related Contacts Count response: " . json_encode($Account->getResponseBody(), JSON_PRETTY_PRINT) . "\n";
//Assuming there are >0 related contacts, filter them by first name contain an `s`
$Filter = $Account->filterRelated('contacts')->contains('first_name', 's');
echo "Filter Def for API: " . json_encode($Filter->compile(),JSON_PRETTY_PRINT) . "\n";
echo "Filter Def for API: " . json_encode($Filter->compile(), JSON_PRETTY_PRINT) . "\n";
$Filter->execute();
echo "Response:" . json_encode($Account->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
echo "Response:" . json_encode($Account->getResponseBody(), JSON_PRETTY_PRINT) . "\n";
} else {
echo "Could not login.";
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');
Expand Down
4 changes: 2 additions & 2 deletions examples/ModuleEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

try {
if ($SugarAPI->isAuthenticated()) {
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";

$Enum = $SugarAPI->enum('Accounts', 'account_type')->execute();
echo "Account Type options: " . json_encode($Enum->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
echo "Account Type options: " . json_encode($Enum->getResponseBody(), JSON_PRETTY_PRINT) . "\n";
} else {
echo "Could not login.";
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');
Expand Down
4 changes: 2 additions & 2 deletions examples/NoteAttachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
$SugarAPI = new \Sugarcrm\REST\Client\SugarAPI($server, $credentials);
try {
if ($SugarAPI->isAuthenticated()) {
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";

$Note = $SugarAPI->note()->set("name", "Test");
echo "Creating Note with multiple attachments: ";
Expand All @@ -34,7 +34,7 @@
//Add attachment_list field to retrieve request so we can see uploaded files
$Note->addField('attachment_list');
$Note->retrieve();
echo "Attachments: " . json_encode($Note->attachment_list,JSON_PRETTY_PRINT) . "\n";
echo "Attachments: " . json_encode($Note->attachment_list, JSON_PRETTY_PRINT) . "\n";
} else {
echo "Could not login.";
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');
Expand Down
8 changes: 4 additions & 4 deletions examples/RelateRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
$SugarAPI = new \Sugarcrm\REST\Client\SugarApi($server, $credentials);
try {
if ($SugarAPI->isAuthenticated()) {
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";
$Account = $SugarAPI->module('Accounts')->set("name", "Relate Records Test");
$Account->save();
echo "Created Account {$Account['id']}: " . json_encode($Account->toArray(),JSON_PRETTY_PRINT) . "\n";
echo "Created Account {$Account['id']}: " . json_encode($Account->toArray(), JSON_PRETTY_PRINT) . "\n";

$Opportunity = $SugarAPI->module('Opportunities');
$Opportunity['name'] = 'Test Opportunity';
$Opportunity['description'] = 'This opportunity was created via the SugarCRM PHP REST Client v1 to test creating relationships.';
$Opportunity->save();
echo "Created Opportunity {$Opportunity['id']}: " . json_encode($Opportunity->toArray(),JSON_PRETTY_PRINT) . "\n";
echo "Created Opportunity {$Opportunity['id']}: " . json_encode($Opportunity->toArray(), JSON_PRETTY_PRINT) . "\n";

echo "Relating Opportunity to Account: ";
$Account->relate('opportunities', $Opportunity['id']);
echo "Response: " . json_encode($Account->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
echo "Response: " . json_encode($Account->getResponseBody(), JSON_PRETTY_PRINT) . "\n";
} else {
echo "Could not login.";
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');
Expand Down
6 changes: 3 additions & 3 deletions examples/Sudo.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
$SugarAPI = new \Sugarcrm\REST\Client\SugarApi($server, $credentials);
try {
if ($SugarAPI->isAuthenticated()) {
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";
if ($SugarAPI->sudo('will')) {
echo "Sudo'd to will. Token: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
echo "Sudo'd to will. Token: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";
$Me = $SugarAPI->me();
$Me->retrieve();
echo "User: " . json_encode($Me->toArray(),JSON_PRETTY_PRINT) . "\n";
echo "User: " . json_encode($Me->toArray(), JSON_PRETTY_PRINT) . "\n";
}
} else {
echo "Could not login.";
Expand Down
6 changes: 3 additions & 3 deletions examples/include.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
require_once __DIR__ . '/../vendor/autoload.php';

$server = 'localhost';
$credentials = array(
$credentials = [
'username' => 'admin',
'password' => 'asdf',
'platform' => 'base'
);
'platform' => 'base',
];
2 changes: 1 addition & 1 deletion src/Auth/SugarOAuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected function generateUniqueCacheString(array $creds): string
$key = '';
try {
$ep = $this->getActionEndpoint(self::ACTION_AUTH);
$key = preg_replace("/\/rest\/v[^\/]+\//","",$ep->getBaseUrl());
$key = preg_replace("/\/rest\/v[^\/]+\//", "", $ep->getBaseUrl());
} catch (\Exception) {
$this->getLogger()->info("Cannot use server in cache string.");
}
Expand Down
13 changes: 6 additions & 7 deletions src/Endpoint/Abstracts/AbstractSugarBeanEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ abstract class AbstractSugarBeanEndpoint extends ModelEndpoint implements SugarE
protected static array $_DEFAULT_PROPERTIES = [
self::PROPERTY_URL => '$module/$id/$:action/$:actionArg1/$:actionArg2/$:actionArg3',
self::PROPERTY_HTTP_METHOD => 'GET',
self::PROPERTY_AUTH => true
self::PROPERTY_AUTH => true,
];

/**
Expand Down Expand Up @@ -380,7 +380,7 @@ public function relate(string $linkName, string $related_id): static
*/
public function auditLog(?int $limit = null): AuditLog
{
$auditCollection = new AuditLog([],['module' => $this->getModule(), 'id' => $this->get('id')]);
$auditCollection = new AuditLog([], ['module' => $this->getModule(), 'id' => $this->get('id')]);

if ($limit !== null) {
$auditCollection->setLimit($limit);
Expand Down Expand Up @@ -543,12 +543,11 @@ protected function configureFileUploadQueryParams(): array
];

if ($this->_deleteFileOnFail) {
$Client = $this->getClient();
if ($Client) {
$data['platform'] = $Client->getPlatform();
$token = $Client->getAuth()->getTokenProp('access_token');
if (!empty($this->_client)) {
$data['platform'] = $this->getClient()->getPlatform();
$token = $this->getClient()->getAuth()->getTokenProp('access_token');
if ($token) {
$data['oauth_token'] = $Client->getAuth()->getTokenProp('access_token');
$data['oauth_token'] = $this->getClient()->getAuth()->getTokenProp('access_token');
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Endpoint/AuditLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ class AuditLog extends SugarBeanCollection
self::PROPERTY_URL => '$module/$id/audit',
self::PROPERTY_AUTH => true,
];
}
}
4 changes: 1 addition & 3 deletions src/Endpoint/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

use Sugarcrm\REST\Endpoint\Abstracts\AbstractSugarCollectionEndpoint;

class Collection extends AbstractSugarCollectionEndpoint
{
}
class Collection extends AbstractSugarCollectionEndpoint {}
4 changes: 2 additions & 2 deletions src/Endpoint/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function addAttachments(array $files, bool $async = true): self
if ($async) {
$responses = Utils::unwrap($promises);
$Note = new Note();
foreach($responses as $response){
foreach ($responses as $response) {
$Note->setResponse($response);
$this->parseAttachmentUploadResponse($Note->getResponseBody());
}
Expand All @@ -51,4 +51,4 @@ public function addAttachments(array $files, bool $async = true): self

return $this;
}
}
}
4 changes: 1 addition & 3 deletions src/Endpoint/Generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

use Sugarcrm\REST\Endpoint\Abstracts\AbstractSugarEndpoint;

class Generic extends AbstractSugarEndpoint
{
}
class Generic extends AbstractSugarEndpoint {}
Loading