Skip to content
This repository was archived by the owner on Oct 29, 2025. It is now read-only.

Commit 8ca8bde

Browse files
Merge pull request #44 from MichaelJ2324/2.0
SUPP-1255, SUPP-1256
2 parents 6dbd829 + 873ff5e commit 8ca8bde

File tree

74 files changed

+766
-230
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+766
-230
lines changed

examples/AuditLog.php

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
11
<?php
2+
/**
3+
* ©[2019] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
4+
*/
25

36
require_once 'include.php';
47

58
$SugarAPI = new \Sugarcrm\REST\Client\Sugar7API($server,$credentials);
69
try{
7-
$SugarAPI->login();
8-
echo "Logged In: <pre>";
9-
print_r($SugarAPI->getAuth()->getToken()->access_token);
10-
echo "</pre>";
11-
$Account = $SugarAPI->module('Accounts')->set("name","Audit Log Test");
12-
$Account->save();
13-
echo "<pre>Created Account: {$Account['id']}</pre><br>";
14-
$Account->set('phone_office','555-555-5555');
15-
$Account['name'] = 'Audit Log Test - Updated';
16-
$Account['assigned_user_id'] = 'seed_max_id';
17-
$Account->save();
18-
echo "<pre> Account Updated: <br>".print_r($Account->asArray(),true)."</pre><br>";
19-
$Account->audit();
20-
echo "<pre> Audit Log:".print_r($Account->getResponse()->getBody(),true)."</pre><br>";
10+
if ($SugarAPI->login()){
11+
echo "Logged In: ";
12+
pre($SugarAPI->getAuth()->getToken());
13+
$Account = $SugarAPI->module('Accounts')->set("name","Audit Log Test");
14+
$Account->save();
15+
pre("Created Account: {$Account['id']}");
16+
$Account->set('phone_office','555-555-5555');
17+
$Account['name'] = 'Audit Log Test - Updated';
18+
$Account['assigned_user_id'] = 'seed_max_id';
19+
$Account->save();
20+
echo "Account Updated:";
21+
pre($Account->asArray());
22+
$Account->audit();
23+
echo "Audit Log: ";
24+
pre($Account->getResponse()->getBody());
25+
} else {
26+
echo "Could not login.";
27+
pre($SugarAPI->getAuth()->getActionEndpoint('authenticate')->getResponse());
28+
}
2129
}catch (Exception $ex){
22-
echo "<pre>";
23-
//print_r($SugarAPI);
24-
echo "</pre>";
25-
print $ex->getMessage();
30+
echo "Error Occurred: ";
31+
pre($ex->getMessage());
32+
pre($ex->getTraceAsString());
2633
}

examples/CRUD.php

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,39 @@
11
<?php
2+
/**
3+
* ©[2019] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
4+
*/
25

36
require_once 'include.php';
47

58
$SugarAPI = new \Sugarcrm\REST\Client\Sugar7API($server,$credentials);
69
try{
7-
$SugarAPI->login();
8-
echo "<pre>";
9-
print_r($SugarAPI->getAuth()->getToken()->access_token);
10-
echo "</pre>";
11-
$Account = $SugarAPI->module('Accounts')->set("name","Test")->set("phone_office","555-555-5555");
12-
echo "<pre> Account:".print_r($Account->asArray(),true)."</pre><br>";
13-
$Account->save();
14-
echo "<pre> Saved Account ID: {$Account['id']}</pre><br>";
15-
$Account->set('employees','100');
16-
$Account['shipping_address_city'] = 'Indianapolis';
17-
$Account->save();
18-
echo "<pre> Account Updated: <br>".print_r($Account->asArray(),true)."</pre>";
19-
$Account2 = $SugarAPI->module('Accounts',$Account['id']);
20-
$Account2->retrieve();
21-
echo "<pre> Account2:".print_r($Account2->asArray(),true)."</pre><br>";
22-
$Account2->delete();
23-
echo "Account Deleted. <br><pre>".print_r($Account2->getResponse(),true)."</pre>";
10+
if ($SugarAPI->login()){
11+
echo "Logged In: ";
12+
pre($SugarAPI->getAuth()->getToken());
13+
$Account = $SugarAPI->module('Accounts')->set("name","Test")->set("phone_office","555-555-5555");
14+
echo "Creating Account: ";
15+
pre($Account->asArray());
16+
$Account->save();
17+
pre("Saved Account ID: {$Account['id']}");
18+
$Account->set('employees','100');
19+
$Account['shipping_address_city'] = 'Indianapolis';
20+
echo "Changing fields employees and shipping address...<br>";
21+
$Account->save();
22+
echo "Account Updated: ";
23+
pre($Account->asArray());
24+
$Account2 = $SugarAPI->module('Accounts',$Account['id']);
25+
$Account2->retrieve();
26+
echo "Retrieving the Account Again...<br>";
27+
pre($Account2->asArray());
28+
$Account2->delete();
29+
echo "Account Deleted. Response: ";
30+
pre($Account2->getResponse());
31+
} else {
32+
echo "Could not login.";
33+
pre($SugarAPI->getAuth()->getActionEndpoint('authenticate')->getResponse());
34+
}
2435
}catch (Exception $ex){
25-
echo "<pre>";
26-
//print_r($SugarAPI);
27-
echo "</pre>";
28-
print $ex->getMessage();
36+
echo "Error Occurred: ";
37+
pre($ex->getMessage());
38+
pre($ex->getTraceAsString());
2939
}

examples/DuplicateCheck.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* ©[2019] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
4+
*/
5+
6+
require_once 'include.php';
7+
8+
$SugarAPI = new \Sugarcrm\REST\Client\Sugar7API($server,$credentials);
9+
10+
try{
11+
if ($SugarAPI->login()){
12+
echo "Logged In: ";
13+
pre($SugarAPI->getAuth()->getToken());
14+
$Account = $SugarAPI->module('Accounts')->set("name","DuplicateCheck Test");
15+
$Account->save();
16+
pre("Account Created: {$Account['id']}");
17+
$a = $Account->asArray();
18+
unset($a['id']);
19+
echo "Running duplicateCheck for Account: ";
20+
pre($a);
21+
$Account->duplicateCheck();
22+
pre($Account->getResponse()->getBody());
23+
} else {
24+
echo "Could not login.";
25+
pre($SugarAPI->getAuth()->getActionEndpoint('authenticate')->getResponse());
26+
}
27+
}catch (Exception $ex){
28+
echo "Error Occurred: ";
29+
pre($ex->getMessage());
30+
}

examples/Favorite.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
<?php
2+
/**
3+
* ©[2019] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
4+
*/
25

36
require_once 'include.php';
47

58
$SugarAPI = new \Sugarcrm\REST\Client\Sugar7API($server,$credentials);
69

710
try{
8-
$SugarAPI->login();
9-
echo "Logged In: <pre>";
10-
print_r($SugarAPI->getAuth()->getToken()->access_token);
11-
echo "</pre>";
12-
$Account = $SugarAPI->module('Accounts')->set("name","Favorite Test");
13-
$Account->save();
14-
echo "<pre> Account Created: {$Account['id']}</pre><br>";
15-
$Account->favorite();
16-
echo "<pre> Account added to Favorites: <br>".print_r($Account,true)."</pre>";
11+
if ($SugarAPI->login()){
12+
echo "Logged In: <pre>";
13+
print_r($SugarAPI->getAuth()->getToken()->access_token);
14+
echo "</pre>";
15+
$Account = $SugarAPI->module('Accounts')->set("name","Favorite Test");
16+
$Account->save();
17+
echo "<pre> Account Created: {$Account['id']}</pre><br>";
18+
$Account->favorite();
19+
echo "<pre> Account added to Favorites: <br>".print_r($Account,true)."</pre>";
20+
} else {
21+
echo "Could not login.";
22+
pre($SugarAPI->getAuth()->getActionEndpoint('authenticate')->getResponse());
23+
}
1724
}catch (Exception $ex){
18-
echo "<pre>";
19-
//print_r($SugarAPI);
20-
echo "</pre>";
21-
print $ex->getMessage();
25+
echo "Error Occurred: ";
26+
pre($ex->getMessage());
2227
}

examples/FileManipulation.php

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,39 @@
66
if (file_exists($file) && is_readable($file)) {
77
$SugarAPI = new \Sugarcrm\REST\Client\Sugar7API($server, $credentials);
88
try {
9-
$SugarAPI->login();
10-
echo "<pre>";
11-
print_r($SugarAPI->getAuth()->getToken()->access_token);
12-
echo "</pre>";
13-
$Note = $SugarAPI->module('Notes')->set("name", "Test");
14-
echo "<pre> Note:" . print_r($Note->asArray(), true) . "</pre><br>";
15-
$Note->save();
16-
echo "<pre> Saved Note ID: {$Note['id']}</pre><br>";
17-
echo "Attempting to attach $file";
18-
$Note->attachFile('filename', $file,TRUE,'text/plain','testtest.txt');
19-
$response = $Note->getResponse()->getBody();
20-
//echo "<pre>" . print_r($Note->getRequest(), true) . "</pre>";
21-
echo "File uploaded: <pre>" . print_r($response,true) . "</pre>";
9+
if ($SugarAPI->login()){
10+
echo "Logged In: ";
11+
pre($SugarAPI->getAuth()->getToken());
12+
$Note = $SugarAPI->module('Notes')->set("name", "Test");
13+
echo "Creating Note: ";
14+
pre($Note->asArray());
15+
$Note->save();
16+
echo "Saved Note ID: {$Note['id']}<br>";
17+
echo "Attempting to attach $file...";
18+
$Note->attachFile('filename', $file,TRUE,'text/plain','testtest.txt');
19+
$response = $Note->getResponse()->getBody();
20+
//echo "<pre>" . print_r($Note->getRequest(), true) . "</pre>";
21+
echo "File uploaded: ";
22+
pre($response);
2223

23-
$Note = $SugarAPI->module('Notes');
24-
$Note->tempFile('filename',$file);
25-
$response = $Note->getResponse()->getBody();
26-
echo "<pre>" . print_r($Note->getRequest(), true) . "</pre>";
27-
echo "File uploaded: <pre>" . print_r($response,true) . "</pre>";
28-
$Note->set('name','This is a test');
29-
$Note->save();
30-
echo "<pre> Note ID: {$Note['id']}</pre><br>";
31-
echo "<pre>" . print_r($Note->getRequest(), true) . "</pre>";
24+
$Note = $SugarAPI->module('Notes');
25+
echo "Uploading temp file for new note...";
26+
$Note->tempFile('filename',$file);
27+
$response = $Note->getResponse()->getBody();
28+
pre($Note->getRequest());
29+
echo "File uploaded: ";
30+
pre($response);
31+
$Note->set('name','This is a test');
32+
$Note->save();
33+
echo "Note ID: {$Note['id']}<br>";
34+
pre($Note->getRequest());
35+
} else {
36+
echo "Could not login.";
37+
pre($SugarAPI->getAuth()->getActionEndpoint('authenticate')->getResponse());
38+
}
3239
} catch (Exception $ex) {
33-
echo "<pre>";
34-
//print_r($SugarAPI);
35-
echo "</pre>";
36-
print $ex->getMessage();
40+
echo "Error Occurred: ";
41+
pre($ex->getMessage());
3742
}
3843
} else {
3944
if (!file_exists($file)){

examples/FilterAPI.php

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,50 @@
44

55
$SugarAPI = new \Sugarcrm\REST\Client\Sugar7API($server,$credentials);
66
try{
7-
$SugarAPI->login();
8-
echo "<pre>";
9-
print_r($SugarAPI->getAuth()->getToken()->access_token);
10-
echo "</pre>";
11-
$Accounts = $SugarAPI->list('Accounts');
12-
$Accounts->filter()->and()
13-
->or()
14-
->starts('name','s')
15-
->contains('name','test')
16-
->endOr()
17-
->equals('assigned_user_id','seed_max_id')
18-
->endAnd();
19-
echo "<pre> Filter Accounts that are assigned to User Max, and that either start with an S or contain 'test' in the name: ".print_r($Accounts->filter()->compile(),true)."</pre><br>";
20-
$Accounts->filter()->execute();
21-
echo "<pre> Response:".print_r($Accounts->getResponse()->getBody(),true)."</pre><br>";
7+
if ($SugarAPI->login()){
8+
echo "Logged In: ";
9+
pre($SugarAPI->getAuth()->getToken());
10+
$Accounts = $SugarAPI->list('Accounts');
11+
$Accounts->filter()->and()
12+
->or()
13+
->starts('name','s')
14+
->contains('name','test')
15+
->endOr()
16+
->equals('assigned_user_id','seed_max_id')
17+
->endAnd();
18+
echo "Filtering Accounts that are assigned to User Max, and that either start with an S or contain 'test' in the name: ";
19+
pre($Accounts->filter()->compile());
20+
$Accounts->count();
21+
echo "Running Count Request: ";
22+
pre($Accounts->getResponse()->getBody());
23+
echo "Running Filter Request: ";
24+
$Accounts->filter()->execute();
25+
echo "Request: ";
26+
pre($Accounts->getRequest());
27+
echo "Accounts: ";
28+
pre($Accounts->asArray());
29+
$Accounts->clear();
30+
$Accounts->filter(true);
31+
echo "Filtering Accounts that are created between dates, or in the last 7 days: ";
32+
$Accounts->filter()->or()->date('date_entered')
33+
->between(array("2019-01-01","2019-02-01"))
34+
->endDate()
35+
->date('date_entered')
36+
->last7Days()
37+
->endDate()
38+
->endOr();
39+
pre($Accounts->filter()->compile());
40+
$Accounts->filter()->execute();
41+
echo "Request: ";
42+
pre($Accounts->getRequest());
43+
echo "Accounts: ";
44+
pre($Accounts->asArray());
45+
} else {
46+
echo "Could not login.";
47+
pre($SugarAPI->getAuth()->getActionEndpoint('authenticate')->getResponse());
48+
}
2249
}catch (Exception $ex){
23-
echo "<pre>";
24-
//print_r($SugarAPI);
25-
echo "</pre>";
26-
print $ex->getMessage();
50+
echo "Error Occurred: ";
51+
pre($ex->getMessage());
52+
pre($ex->getTraceAsString());
2753
}

examples/FilterRelated.php

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
<?php
22
/**
3-
* ©[2017] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
3+
* ©[2019] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
44
*/
55

66
require_once 'include.php';
77

88
$SugarAPI = new \Sugarcrm\REST\Client\Sugar7API($server,$credentials);
99
try{
10-
$SugarAPI->login();
11-
echo "<pre>";
12-
print_r($SugarAPI->getAuth()->getToken()->access_token);
13-
echo "</pre>";
14-
$Accounts = $SugarAPI->list('Accounts');
15-
$Accounts->fetch();
16-
$Account = $Accounts->at(1);
17-
$Account->getRelated('contacts',true);
18-
echo $Account->getRequest()->getURL()."<br>";
19-
echo "<pre> Response:".print_r($Account->getResponse()->getBody(),true)."</pre><br>";
20-
$Filter = $Account->filterRelated('contacts')->contains('first_name','s');
21-
echo "<pre> Filter Contacts related to Account {$account['id']} where first_name contains an 's': ".print_r($Filter->compile(),true)."</pre><br>";
22-
$Filter->execute();
23-
echo "<pre> Response:".print_r($Account->getResponse()->getBody(),true)."</pre><br>";
10+
if ($SugarAPI->login()){
11+
echo "<pre>";
12+
print_r($SugarAPI->getAuth()->getToken()->access_token);
13+
echo "</pre>";
14+
$Accounts = $SugarAPI->list('Accounts');
15+
$Accounts->fetch();
16+
$Account = $Accounts->at(1);
17+
$Account->getRelated('contacts',true);
18+
echo $Account->getRequest()->getURL()."<br>";
19+
echo "<pre> Response:".print_r($Account->getResponse()->getBody(),true)."</pre><br>";
20+
$Filter = $Account->filterRelated('contacts')->contains('first_name','s');
21+
echo "<pre> Filter Contacts related to Account {$account['id']} where first_name contains an 's': ".print_r($Filter->compile(),true)."</pre><br>";
22+
$Filter->execute();
23+
echo "<pre> Response:".print_r($Account->getResponse()->getBody(),true)."</pre><br>";
24+
} else {
25+
echo "Could not login.";
26+
pre($SugarAPI->getAuth()->getActionEndpoint('authenticate')->getResponse());
27+
}
2428
}catch (Exception $ex){
25-
echo "<pre>";
26-
//print_r($SugarAPI);
27-
echo "</pre>";
28-
print $ex->getMessage();
29+
echo "Error Occurred: ";
30+
pre($ex->getMessage());
2931
}

0 commit comments

Comments
 (0)