-
Notifications
You must be signed in to change notification settings - Fork 31
SugarEndpoints
The following is the List of Sugar 7 REST API Endpoints that currently can be used with the Sugar REST PHP Client. Please note, that
although all methods can be used, some API methods may not exist for a particular version of Sugar 7 (i.e. Bulk).
Each Endpoint listed below documents the following:
- The Method to use on the Client Object to make the API Request.
- The Arguments (Endpoint Options), which are required for proper execution.
- These arguments are passed directly into the dynamic method and used to populate the API Endpoint URL
- The Execution arguments (Endpoint Data), outline the short-hand form of data that needs to be passed to the Endpoint's
execute()
method.
- The full set of request data that can be passed to any given Endpoint and is listed in the associated SugarCRM API Endpoint documentation. To use the full set of data, please review the Endpoint documentation.
- The Example, shows the usage of the Endpoint and execution with the provided SugarAPI Client.
- Please review the Response documentation for further understanding of how to retrieve and utilize the responses from the API Endpoint after execution.
Create, Read, Update and Delete records via the Sugar 7 REST API
Create a record in a module.
Utilizes the <module> - POST API Endpoint
SugarAPI\SDK\Endpoint\POST\Module
Name | Type | Description |
---|---|---|
$module | string | The Sugar module you wish to create a record |
Name | Type | Description |
---|---|---|
$record | array | An associative array defining the module fields and their values for the new record |
$module = 'Accounts'; $record = array( 'name' => 'Test Account', 'account_type' => 'Customer' ); $SugarAPI = new \SugarAPI\SDK\SugarAPI($server,$creds); $SugarAPI->login(); $SugarAPI->createRecord($module)->execute($record);
Retrieve a record from a module by its ID.
Utilizes the <module>/:record - GET API Endpoint
SugarAPI\SDK\Endpoint\GET\ModuleRecord
Name | Type | Description |
---|---|---|
$module | string | The Sugar module of the record |
$id | string | The ID of the record you wish to retrieve |
$module = 'Accounts'; $id = '12345' $SugarAPI = new \SugarAPI\SDK\SugarAPI(); $SugarAPI->login(); $SugarAPI->getRecord($module,$id)->execute();
Retrieve a list of module records, and filter those records using the Filter API.
Utilizes the <module>/filter - POST API Endpoint
SugarAPI\SDK\Endpoint\POST\ModuleFilter
Name | Type | Description |
---|---|---|
$module | string | The Sugar module you wish to retrieve records from |
Name | Type | Description |
---|---|---|
$filterArgs | array | An associative array defining the arguments for the Filter API. See above linked article on the API Endpoint for the available arguments |
$module = 'Accounts'; $filterArgs = array( 'max_num' => 5, 'offset' => 0, 'filter' => array( 'name' => array( $contains => 'test' ) ), fields => 'id,name,account_type' ); $SugarAPI = new \SugarAPI\SDK\SugarAPI($server,$creds); $SugarAPI->login(); $SugarAPI->filterRecords($module)->execute($filterArgs);
Update a specific record in a module.
Utilizes the <module>/:record - PUT API Endpoint
SugarAPI\SDK\Endpoint\PUT\ModuleRecord
Name | Type | Description |
---|---|---|
$module | string | The Sugar module you wish to update a record in |
$id | string | The ID of the record |
Name | Type | Description |
---|---|---|
$record | mixed | Could be an array or \StdClass Object that defines the record attributes that should be updated |
$module = 'Accounts'; $id = '12345'; $record = array( 'name' => 'Test updated' ); $SugarAPI = new \SugarAPI\SDK\SugarAPI($server,$creds); $SugarAPI->login(); $SugarAPI->updateRecord($module,$id)->execute($record);
Delete a specific record in a module.
Utilizes the <module>/:record - DELETE API Endpoint
SugarAPI\SDK\Endpoint\DELETE\ModuleRecord
Name | Type | Description |
---|---|---|
$module | string | The Sugar module you wish to delete a record in |
$id | string | The ID of the record |
$module = 'Accounts'; $id = '12345'; $SugarAPI = new \SugarAPI\SDK\SugarAPI($server,$creds); $SugarAPI->login(); $SugarAPI->deleteRecord($module,$id)->execute();
Login to Sugar REST API and retrieve an OAuth 2.0 Access Token.
Utilizes the oauth2/token - POST API Endpoint
SugarAPI\SDK\Endpoint\POST\OAuth2Token
Name | Type | Description |
---|---|---|
$credentials | array | An associative array containing the required credentials for the Sugar API. The five properties that should be passed are client_id, client_secret, platform, username and password. |
$credentials = array( 'client_id' => 'test_client', 'client_secret' => 'test_secret', 'platform' => 'base', 'username' => 'user', 'password' => 'password' ); $SugarAPI = new \SugarAPI\SDK\SugarAPI(); $SugarAPI->oauth2Token()->execute($credentials);
Refresh an OAuth 2.0 authentication token for the Sugar REST API.
Utilizes the oauth2/token - POST API Endpoint.
SugarAPI\SDK\Endpoint\POST\RefreshToken
Name | Type | Description |
---|---|---|
$refreshGrant | array | An associative array containing the required refresh grant properties for the Sugar API. The properties that should be passed are refresh_token, client_id, and client_secret. |
$SugarAPI = new \SugarAPI\SDK\SugarAPI($server,$creds); $SugarAPI->login(); $token = $SugarAPI->getToken(); $refreshGrant = array( 'client_id' => 'test_client', 'client_secret' => 'test_secret', 'refresh_token' => $token->refresh_token ); $SugarAPI->oauth2Refresh()->data($refreshGrant)->execute();
Logout of the Sugar REST API.
Utilizes the oauth2/logout - POST API Endpoint
SugarAPI\SDK\Endpoint\POST\OAuth2Logout
$SugarAPI = new \SugarAPI\SDK\SugarAPI($server,$creds); $SugarAPI->login(); $SugarAPI->oauth2Logout()->execute();
Gets the Current User.
Utilizes the me/ - GET API Endpoint
SugarAPI\SDK\Endpoint\GET\Me
$SugarAPI = new \SugarAPI\SDK\SugarAPI($server,$creds); $SugarAPI->login(); $SugarAPI->me()->execute();
Create a related record and link it to a module.
Utilizes the <module>/:record/link/:relationship - POST API Endpoint
SugarAPI\SDK\Endpoint\POST\ModuleRecordRelationship
Name | Type | Description |
---|---|---|
$module | string | The Sugar module you wish to relate a record to |
$id | string | The ID of the record you are relating to |
$relationship_link | string | The name of the relationship link |
Name | Type | Description |
---|---|---|
$record | mixed | Could be an array or \StdClass Object that defines the record attributes that should be created |
$module = 'Accounts'; $id = '12345'; $relationship_link = 'contacts'; $record = array( 'first_name' => 'John', 'last_name' => 'Doe' ); $SugarAPI = new \SugarAPI\SDK\SugarAPI($server,$creds); $SugarAPI->login(); $SugarAPI->createRelated($module,$id,$relationship_link)->execute($contactRecord);
Get a list of related records to a particular module's record. Allows for filtering the related records using the Filter API.
Utilizes the <module>/:record/link/:relationship - GET API Endpoint
SugarAPI\SDK\Endpoint\GET\ModuleRecordRelationship
Name | Type | Description |
---|---|---|
$module | string | The Sugar module you wish to retrieve related records from |
$id | string | The ID of the record you are retrieving the relationship from |
$relationship_link | string | The name of the relationship link |
Name | Type | Description |
---|---|---|
$filterArgs | array | An associative array of the filter arguments used to alter the result set |
$module = 'Accounts'; $id = '12345'; $relationship_link = 'contacts'; $filterArgs = array( 'max_num' => 5, 'offset' => 0, 'fields' => 'id,first_name,last_name', 'filter' => array( 'last_name' => array( '$contains' => 'test' ) ), 'order_by' => 'last_name DESC' ); $SugarAPI = new \SugarAPI\SDK\SugarAPI($server,$creds); $SugarAPI->login(); $SugarAPI->filterRelated($module,$id,$relationship_link)->execute($filterArgs);
Retrieve a record, related to a particular module's record.
Utilizes the <module>/:record/link/:relationship/:record_id - GET API Endpoint
SugarAPI\SDK\Endpoint\GET\ModuleRecordLinkRecord
Name | Type | Description |
---|---|---|
$module | string | The Sugar module you wish to retrieve related records from |
$id | string | The ID of the record you are retrieving the relationship from |
$relationship_link | string | The name of the relationship link |
$related_id | string | The ID of the related record |
$module = 'Accounts'; $id = '12345'; $relationship_link = 'contacts'; $related_id = '67890'; $SugarAPI = new \SugarAPI\SDK\SugarAPI($server,$creds); $SugarAPI->login(); $SugarAPI->getRelated($module,$id,$relationship_link,$related_id)->execute();
Relate two records from different modules based on their ID's and the mutual relationship link.
Utilizes the <module>/:record/link/:relationship/:record_id - POST API Endpoint
SugarAPI\SDK\Endpoint\POST\ModuleRecordLinkRecord
Name | Type | Description |
---|---|---|
$module | string | The Sugar module you wish to retrieve related records from |
$id | string | The ID of the record you are retrieving the relationship from |
$relationship_link | string | The name of the relationship link |
$related_id | string | The ID of the related record |
$module = 'Accounts'; $id = '12345'; $relationship_link = 'contacts'; $related_id = '67890'; $SugarAPI = new \SugarAPI\SDK\SugarAPI(); $SugarAPI->login(); $SugarAPI->linkRecords($module,$id,$relationship_link,$related_id)->execute();
Unlink the relationship between two records.
Utilizes the <module>/:record/link/:relationship/:record_id - DELETE API Endpoint
SugarAPI\SDK\Endpoint\DELETE\ModuleRecordLinkRecord
Name | Type | Description |
---|---|---|
$module | string | The Sugar module you wish to unlink related records from |
$id | string | The ID of the record you are removing the relationship from |
$relationship_link | string | The name of the relationship link |
$related_id | string | The ID of the related record |
$module = 'Accounts'; $id = '12345'; $relationship_link = 'contacts'; $related_id = '67890'; $SugarAPI = new \SugarAPI\SDK\SugarAPI($server,$creds); $SugarAPI->login(); $SugarAPI->unlinkRecords($module,$id,$relationship_link,$related_id)->execute();
Search all modules of the system for a particular criteria.
Utilizes the search - GET API Endpoint
SugarAPI\SDK\Endpoint\GET\Search
Name | Type | Description |
---|---|---|
$searchArgs | array | An associative array with the Search arguments |
$searchArgs = array( 'max_num' => 100, 'offset' => 0, 'q' => 'test' ); $SugarAPI = new \SugarAPI\SDK\SugarAPI($server,$creds); $SugarAPI->login(); $SugarAPI->search()->execute($searchArgs);
The Bulk API allows for multiple requests to be submitted to the API at once, and all of the response returned accordingly.
A typical usage of this, might be to request a specific record, and various relationships all at once.
Utilizes the bulk - POST API Endpoint
SugarAPI\SDK\Endpoint\POST\Bulk
Name | Type | Description |
---|---|---|
$endpoints | array | An array of Endpoint Objects |
$SugarAPI = new \SugarAPI\SDK\SugarAPI($server,$creds); $SugarAPI->login(); $Accounts = $SugarAPI->filterRecords('Accounts')->setData(array('max_num'=> 5)); $Contacts = $SugarAPI->filterRecords('Contacts')->setData(array('max_num'=> 1)); $Notes = $SugarAPI->filterRecords('Notes')->setData(array('max_num'=> 3)); $Leads = $SugarAPI->filterRecords('Leads')->setData(array('max_num'=> 2)); $BulkCall = $SugarAPI->bulk()->execute(array( $Accounts, $Contacts, $Notes, $Leads ));
Upload a file to a record. This will add a new file, or overwrite an existing file. Only works on modules that contain a 'file' type field, such as the stock Notes module.
Utilizes the <module>/:record/file/:field - POST API Endpoint
SugarAPI\SDK\Endpoint\POST\ModuleRecordFileField
Name | Type | Description |
---|---|---|
$module | string | The Sugar module you wish to attach a file to |
$id | string | The ID of the record you are adding the file to |
$file_field | string | The name of the "file" type field on the module |
Name | Type | Description |
---|---|---|
$file | string | The path of the file to be uploaded |
$module = 'Notes'; $id = '12345'; $file_field = 'filename'; $file = '/Users/test/file.txt'; $SugarAPI = new \SugarAPI\SDK\SugarAPI($server,$creds); $SugarAPI->login(); $SugarAPI->attachFile($module,$id,$file_field)->execute($file);
Download attached files from records. Only works on modules that contain a 'file' type field, such as the stock Notes module.
Utilizes the <module>/:record/file/:field - GET API Endpoint
SugarAPI\SDK\Endpoint\GET\ModuleRecordFileField
Name | Type | Description |
---|---|---|
$module | string | The Sugar module you wish to attach a file to |
$id | string | The ID of the record you are adding the file to |
$file_field | string | The name of the "file" type field on the module |
Name | Type | Description |
---|---|---|
$downloadDir | string | The path of the file to be uploaded |
Note This Endpoint utilizes a custom 'downloadTo()' method to set the download directory of the File Attachment, rather than passing data to the 'execute()' method. If the download directory is not set, a temp directory is created to store the file using the PHP Temp directory functionality. Please review the File Response documentation for usage on how to retrieve the downloaded file.
$module = 'Notes'; $id = '12345'; $file_field = 'filename'; $downloadDir = '/Users/test/downloads/'; $SugarAPI = new \SugarAPI\SDK\SugarAPI($server,$creds); $SugarAPI->login(); $SugarAPI->getAttachment($module,$id,$file_field)->downloadTo($downloadDir)->execute();
Delete a file from a record. Only works on modules that contain a 'file' type field, such as the stock Notes module.
Utilizes the <module>/:record/file/:field - DELETE API Endpoint
SugarAPI\SDK\Endpoint\DELETE\ModuleRecordFileField
Name | Type | Description |
---|---|---|
$module | string | The Sugar module you wish to attach a file to |
$id | string | The ID of the record you are adding the file to |
$file_field | string | The name of the "file" type field on the module |
$module = 'Notes'; $id = '12345'; $file_field = 'filename'; $SugarAPI = new \SugarAPI\SDK\SugarAPI($server,$creds); $SugarAPI->login(); $SugarAPI->deleteFile($module,$id,$file_field)->execute();
Mark a module record as a favorite.
Utilizes the <module>/:record/favorite - PUT API Endpoint
SugarAPI\SDK\Endpoint\PUT\ModuleRecordFavorite
Name | Type | Description |
---|---|---|
$module | string | The Sugar module where the record resides |
$id | string | The ID of the record you are adding as a favorite |
$module = 'Accounts'; $id = '12345'; $SugarAPI = new \SugarAPI\SDK\SugarAPI($server,$creds); $SugarAPI->login(); $SugarAPI->favorite($module,$id)->execute();
Unmark a module record as a favorite.
Utilizes the <module>/:record/favorite - DELETE API Endpoint
SugarAPI\SDK\Endpoint\DELETE\ModuleRecordFavorite
Name | Type | Description |
---|---|---|
$module | string | The Sugar module where the record resides |
$id | string | The ID of the record you are adding as a favorite |
$module = 'Accounts'; $id = '12345'; $SugarAPI = new \SugarAPI\SDK\SugarAPI($server,$creds); $SugarAPI->login(); $SugarAPI->unfavorite($module,$id)->execute();
Ping the Sugar REST API.
Utilizes the ping - GET API Endpoint
SugarAPI\SDK\Endpoint\GET\Ping
$SugarAPI = new \SugarAPI\SDK\SugarAPI($server,$creds); $SugarAPI->login(); $SugarAPI->ping()->execute();