Skip to content

Commit ec852a0

Browse files
committed
Update Copyright + Update Examples
1 parent ed2f8ed commit ec852a0

37 files changed

+233
-260
lines changed

examples/ArchiveEmail.php

-43
This file was deleted.

examples/AuditLog.php

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,39 @@
11
<?php
22

33
/**
4-
* ©[2024] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
4+
* ©[2025] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
55
*/
66

77
require_once 'include.php';
88

99
$SugarAPI = new \Sugarcrm\REST\Client\SugarAPI($server, $credentials);
1010
try {
11-
if ($SugarAPI->login()) {
11+
if ($SugarAPI->isAuthenticated()) {
12+
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";
13+
// Due to core Bug on Sugar 11+, Audit Log API has a min version of 11_11, so I'm forcing it here
1214
$SugarAPI->setVersion('11_11');
13-
echo "Logged In: ";
14-
pre($SugarAPI->getAuth()->getToken());
15+
1516
$Account = $SugarAPI->module('Accounts')->set("name", "Audit Log Test");
1617
$Account->save();
17-
pre("Created Account: {$Account['id']}");
18+
echo "Created Account: {$Account['id']}\n";
19+
//Update the account to generate Audits
1820
$Account->set('phone_office', '555-555-5555');
1921
$Account['name'] = 'Audit Log Test - Updated';
2022
$Account['assigned_user_id'] = 'seed_max_id';
2123
$Account->save();
22-
echo "Account Updated:";
23-
pre($Account->toArray());
24+
echo "Account Updated: " . json_encode($Account->toArray(),JSON_PRETTY_PRINT) . "\n";
2425
$Account->audit();
25-
echo "Audit Log: ";
26-
pre($Account->getResponseBody());
26+
echo "Audit Log: " . json_encode($Account->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
2727
} else {
2828
echo "Could not login.";
29-
pre($SugarAPI->getAuth()->getActionEndpoint('authenticate')->getResponse());
29+
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');
30+
$response = $oauthEndpoint->getResponse();
31+
if ($response) {
32+
$statusCode = $oauthEndpoint->getResponse()->getStatusCode();
33+
echo "[$statusCode] - " . $oauthEndpoint->getResponse()->getBody()->getContents();
34+
}
3035
}
3136
} catch (Exception $ex) {
32-
echo "Error Occurred: ";
33-
pre($ex->getMessage());
34-
pre($ex->getTraceAsString());
35-
}
37+
echo "Exception Occurred: " . $ex->getMessage();
38+
echo $ex->getTraceAsString();
39+
}

examples/Bulk.php

+18-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
<?php
22

33
/**
4-
* ©[2024] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
4+
* ©[2025] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
55
*/
66

77
require_once 'include.php';
88

99
$SugarAPI = new \Sugarcrm\REST\Client\SugarApi($server, $credentials);
10+
1011
try {
1112
if ($SugarAPI->isAuthenticated()) {
13+
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
14+
1215
$lead1 = $SugarAPI->module("Leads");
1316
$lead2 = $SugarAPI->module("Leads");
1417
$lead1['first_name'] = "Test";
@@ -18,23 +21,27 @@
1821
$lead2->set($lead1->toArray());
1922
//Add 2 to second lead last name to differentiate
2023
$lead2['last_name'] .= "2";
21-
//Set
22-
$lead1->setCurrentAction(\MRussell\REST\Endpoint\ModelEndpoint::MODEL_ACTION_CREATE);
23-
$lead2->setCurrentAction(\MRussell\REST\Endpoint\ModelEndpoint::MODEL_ACTION_CREATE);
24+
//By default a SugarBean Endpoint with no action and ID will do a CREATE API Request
25+
//To change the API used for the Model Endpoint, set the Action
26+
//$lead1->setCurrentAction(\MRussell\REST\Endpoint\ModelEndpoint::MODEL_ACTION_CREATE);
2427
$bulk = $SugarAPI->bulk();
2528
$bulk->setData([
2629
$lead1,
2730
$lead2,
2831
]);
29-
echo json_encode($bulk->getData()->toArray(), JSON_PRETTY_PRINT);
32+
echo "Bulk Request Payload: " . json_encode($bulk->getData()->toArray(), JSON_PRETTY_PRINT) . "\n";
3033
$bulk->execute();
31-
echo json_encode($bulk->getResponseContent(), JSON_PRETTY_PRINT);
34+
echo "Bulk Response: " . json_encode($bulk->getResponseBody(), JSON_PRETTY_PRINT) . "\n";
3235
} else {
3336
echo "Could not login.";
34-
pre($SugarAPI->getAuth()->getActionEndpoint('authenticate')->getResponse());
37+
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');
38+
$response = $oauthEndpoint->getResponse();
39+
if ($response) {
40+
$statusCode = $oauthEndpoint->getResponse()->getStatusCode();
41+
echo "[$statusCode] - " . $oauthEndpoint->getResponse()->getBody()->getContents();
42+
}
3543
}
3644
} catch (Exception $ex) {
37-
echo "Error Occurred: ";
38-
pre($ex->getMessage());
39-
pre($ex->getTraceAsString());
40-
}
45+
echo "Exception Occurred: " . $ex->getMessage();
46+
echo $ex->getTraceAsString();
47+
}

examples/CRUD.php

+27-19
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,48 @@
11
<?php
22

33
/**
4-
* ©[2024] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
4+
* ©[2025] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
55
*/
66

77
require_once 'include.php';
88

99
$SugarAPI = new \Sugarcrm\REST\Client\SugarApi($server, $credentials);
10+
1011
try {
11-
if ($SugarAPI->login()) {
12-
echo "Logged In: ";
13-
pre($SugarAPI->getAuth()->getToken());
14-
$Account = $SugarAPI->module('Accounts')->set("name", "Test")->set("phone_office", "555-555-5555");
15-
echo "Creating Account: ";
16-
pre($Account->toArray());
12+
if ($SugarAPI->isAuthenticated()) {
13+
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
14+
// Create an Account called Test with a phone number
15+
$Account = $SugarAPI->module('Accounts');
16+
// You can set data via Array Access, Object Access, or set methods
17+
$Account->set("name", "Test")
18+
->set("phone_office", "555-555-5555");
19+
$Account['account_type'] = 'Prospect';
20+
$Account->email1 = "[email protected]";
1721
$Account->save();
18-
pre("Saved Account ID: {$Account['id']}");
22+
echo "Saved Account ID: {$Account['id']}\n";
23+
//Update Account
1924
$Account->set('employees', '100');
2025
$Account['shipping_address_city'] = 'Indianapolis';
21-
echo "Changing fields employees and shipping address...<br>";
2226
$Account->save();
23-
echo "Account Updated: ";
24-
pre($Account->toArray());
27+
echo "Account Updated: " . json_encode($Account->toArray(),JSON_PRETTY_PRINT) . "\n";
28+
29+
//Retrieve the Account in a new Object
2530
$Account2 = $SugarAPI->module('Accounts', $Account['id']);
2631
$Account2->retrieve();
27-
echo "Retrieving the Account Again...<br>";
28-
pre($Account2->toArray());
32+
echo "Retrieved Account: " . json_encode($Account2->toArray(),JSON_PRETTY_PRINT) . "\n";
33+
//Delete the Account
2934
$Account2->delete();
30-
echo "Account Deleted. Response: ";
31-
pre($Account2->getResponseBody());
35+
echo "Deleted Response: " . json_encode($Account2->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
3236
} else {
3337
echo "Could not login.";
34-
pre($SugarAPI->getAuth()->getActionEndpoint('authenticate')->getResponse());
38+
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');
39+
$response = $oauthEndpoint->getResponse();
40+
if ($response) {
41+
$statusCode = $oauthEndpoint->getResponse()->getStatusCode();
42+
echo "[$statusCode] - " . $oauthEndpoint->getResponse()->getBody()->getContents();
43+
}
3544
}
3645
} catch (Exception $ex) {
37-
echo "Error Occurred: ";
38-
pre($ex->getMessage());
39-
pre($ex->getTraceAsString());
46+
echo "Exception Occurred: " . $ex->getMessage();
47+
echo $ex->getTraceAsString();
4048
}

examples/DuplicateCheck.php

+15-11
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
<?php
22

33
/**
4-
* ©[2024] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
4+
* ©[2025] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
55
*/
66

77
require_once 'include.php';
88

99
$SugarAPI = new \Sugarcrm\REST\Client\SugarApi($server, $credentials);
1010

1111
try {
12-
if ($SugarAPI->login()) {
13-
echo "Logged In: ";
14-
pre($SugarAPI->getAuth()->getToken());
12+
if ($SugarAPI->isAuthenticated()) {
13+
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
14+
//Create a new Account
1515
$Account = $SugarAPI->module('Accounts')->set("name", "DuplicateCheck Test");
1616
$Account->save();
17-
pre("Account Created: {$Account['id']}");
18-
$a = $Account->toArray();
19-
echo "Running duplicateCheck for Account: ";
17+
echo "Account Created: {$Account['id']}\n";
18+
// Run duplicate check
2019
$Account->duplicateCheck();
21-
pre($Account->getResponseBody());
20+
echo "Response: " . json_encode($Account->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
2221
} else {
2322
echo "Could not login.";
24-
pre($SugarAPI->getAuth()->getActionEndpoint('authenticate')->getResponse());
23+
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');
24+
$response = $oauthEndpoint->getResponse();
25+
if ($response) {
26+
$statusCode = $oauthEndpoint->getResponse()->getStatusCode();
27+
echo "[$statusCode] - " . $oauthEndpoint->getResponse()->getBody()->getContents();
28+
}
2529
}
2630
} catch (Exception $ex) {
27-
echo "Error Occurred: ";
28-
pre($ex->getMessage());
31+
echo "Exception Occurred: " . $ex->getMessage();
32+
echo $ex->getTraceAsString();
2933
}

examples/Favorite.php

+15-11
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
<?php
22

33
/**
4-
* ©[2024] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
4+
* ©[2025] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
55
*/
66

77
require_once 'include.php';
88

99
$SugarAPI = new \Sugarcrm\REST\Client\SugarApi($server, $credentials);
1010

1111
try {
12-
if ($SugarAPI->login()) {
13-
echo "Logged In: <pre>";
14-
print_r($SugarAPI->getAuth()->getToken()->access_token);
15-
echo "</pre>";
12+
if ($SugarAPI->isAuthenticated()) {
13+
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
14+
//Create a new Account
1615
$Account = $SugarAPI->module('Accounts')->set("name", "Favorite Test");
1716
$Account->save();
18-
echo "<pre> Account Created: {$Account['id']}</pre><br>";
17+
echo "Account Created: {$Account['id']}\n";
1918
$Account->favorite();
20-
echo "Account added to Favorites: " . ($Account->my_favorite == 1 ? "TRUE" : "FALSE");
19+
echo "Account added to Favorites: " . ($Account->my_favorite ? "TRUE" : "FALSE") . "\n";
2120
} else {
2221
echo "Could not login.";
23-
pre($SugarAPI->getAuth()->getActionEndpoint('authenticate')->getResponse());
22+
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');
23+
$response = $oauthEndpoint->getResponse();
24+
if ($response) {
25+
$statusCode = $oauthEndpoint->getResponse()->getStatusCode();
26+
echo "[$statusCode] - " . $oauthEndpoint->getResponse()->getBody()->getContents();
27+
}
2428
}
2529
} catch (Exception $ex) {
26-
echo "Error Occurred: ";
27-
pre($ex->getMessage());
28-
}
30+
echo "Exception Occurred: " . $ex->getMessage();
31+
echo $ex->getTraceAsString();
32+
}

examples/FileManipulation.php

+13-25
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* ©[2024] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
4+
* ©[2025] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
55
*/
66

77
use GuzzleHttp\Middleware;
@@ -11,46 +11,34 @@
1111

1212
if (file_exists($file) && is_readable($file)) {
1313
$SugarAPI = new \Sugarcrm\REST\Client\SugarAPI($server, $credentials);
14-
$history = [];
15-
$SugarAPI->getHandlerStack()->push(Middleware::history($history), 'history');
1614
try {
17-
if ($SugarAPI->login()) {
18-
echo "Logged In: ";
19-
pre($SugarAPI->getAuth()->getToken());
15+
if ($SugarAPI->isAuthenticated()) {
16+
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
17+
2018
$Note = $SugarAPI->module('Notes')->set("name", "Test");
21-
echo "Creating Note: ";
22-
pre($Note->toArray());
19+
//Create a note with subject
2320
$Note->save();
2421
echo "Saved Note ID: {$Note['id']}<br>";
2522
echo "Attempting to attach $file...";
2623
$Note->attachFile('filename', $file, true, 'testtest.txt');
27-
$response = $Note->getResponseBody();
28-
//echo "<pre>" . print_r($Note->getRequest(), true) . "</pre>";
29-
echo "File uploaded: ";
30-
pre($response);
24+
echo "File uploaded: " . json_encode($Note->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
3125

3226
$Note = $SugarAPI->module('Notes');
3327
echo "Uploading temp file for new note...";
3428
$Note->tempFile('filename', $file);
35-
$response = $Note->getResponseBody();
36-
echo "File uploaded: ";
37-
pre($response);
29+
echo "Temp File uploaded: " . json_encode($Note->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
3830
$Note->set('name', 'This is a test');
3931
$Note->save();
40-
echo "Note ID: {$Note['id']}<br>";
32+
echo "Note ID: {$Note['id']}\n";
4133
} else {
4234
echo "Could not login.";
43-
pre($SugarAPI->getAuth()->getActionEndpoint('authenticate')->getResponse());
35+
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');
36+
$statusCode = $oauthEndpoint->getResponse()->getStatusCode();
37+
echo "[$statusCode] - " . $oauthEndpoint->getResponse()->getBody()->getContents();
4438
}
4539
} catch (Exception $ex) {
46-
echo "Error Occurred: ";
47-
pre($ex->getMessage());
48-
} finally {
49-
foreach ($history as $item) {
50-
if (isset($item['request'])) {
51-
pre($item['request']->getBody()->getContents());
52-
}
53-
}
40+
echo "Exception Occurred: " . $ex->getMessage();
41+
echo $ex->getTraceAsString();
5442
}
5543
} else {
5644
if (!file_exists($file)) {

0 commit comments

Comments
 (0)