Created
December 12, 2011 15:44
-
-
Save ashfame/1467944 to your computer and use it in GitHub Desktop.
SugarCRM REST API call examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* SugarCRM RESTS API Call examples | |
* | |
* REST API Wrapper - https://github.com/asakusuma/SugarCRM-REST-API-Wrapper-Class | |
*/ | |
?> | |
<!doctype html> | |
<head> | |
<meta charset="utf-8"> | |
<title>SugarCRM REST API Wrapper Class Example</title> | |
</head> | |
<body> | |
<pre> | |
<?php | |
if ( !file_exists( 'sugar_rest.php' ) ) { | |
echo 'You need to put the REST API wrapper in the same directory. Get it from here - <a href="https://github.com/asakusuma/SugarCRM-REST-API-Wrapper-Class">SugarCRM REST API Wrapper</a>'; | |
die(); | |
} | |
require_once( 'sugar_rest.php' ); | |
$sugar = new Sugar_REST(); | |
$error = $sugar->get_error(); | |
if ( $error !== FALSE ) { | |
echo $error['name']; | |
} | |
/** | |
* Get a list of Accounts in SugarCRM | |
*/ | |
$results = $sugar->get_with_related( | |
'Accounts', | |
array( | |
'Accounts' => array( 'id', 'name' ), | |
//'contacts' => array( 'id', 'first_name', 'last_name', 'primary_address_city', 'primary_address_state', 'primary_address_street' ) | |
), | |
array( 'limit' => '999' ) | |
); | |
// NOTE: $results['entry_list'] is an array containing all the accounts | |
echo '<p>There are '.count( $results['entry_list'] ).' accounts</p>'; | |
echo '<ol>'; | |
foreach ( $results['entry_list'] as $entry ) | |
echo "<li>{$entry['name_value_list']['name']['value']} ({$entry['id']})</li>"; // Format: NAME (ID) | |
echo '</ol>'; | |
/** | |
* Get a list of Contacts under a particular Account in SugarCRM | |
* | |
* $results['relationship_list'] of API call to retreieve Accounts list doesn't return all the contacts under accounts (limited to 50), so we will refetch contacts by specifying the account ID | |
*/ | |
$results = $sugar->get_with_related( | |
'Accounts', | |
array( | |
'Accounts' => array( 'id' ), | |
'contacts' => array( 'id', 'first_name', 'last_name', 'primary_address_city', 'primary_address_state', 'primary_address_street' ) | |
), | |
//array("limit" => "999"), | |
array("where" => "accounts.id = 'd135a3a1-d637-b383-dbbd-4e03ece62580'") // ID for a particular account, here it is of Hanson | |
); | |
$records = $results['relationship_list'][0][0]['records']; | |
echo '<p>There are '.count( $records ).' contacts under this account</p>'; | |
echo '<ol>'; | |
foreach( $records as $record ) { | |
echo '<li>'; | |
echo '<ul>'; | |
foreach( $record as $field ) | |
echo "<li>{$field['name']} === {$field['value']}</li>"; | |
echo '</ul>'; | |
echo '</li>'; | |
} | |
echo '</ol>'; |
I want to insert leads using API calls to sugarcrm. Can you share any simple url to me, where I will get an proper idea. Thanks in advance
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for publishing this! It helped me a lot. I'm struggling on how to search for a user by email though. Do you have any idea how to do this?