Skip to content
Emmanuel D edited this page Mar 24, 2017 · 11 revisions

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:

  1. The Method to use on the Client Object to make the API Request.
  2. 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
  1. 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.
  1. 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.

CRUD Methods

Create, Read, Update and Delete records via the Sugar 7 REST API

createRecord()

Create a record in a module.
Utilizes the <module> - POST API Endpoint

Class

SugarAPI\SDK\Endpoint\POST\Module

Arguments

Name Type Description
$module string The Sugar module you wish to create a record

Execution

Name Type Description
$record array An associative array defining the module fields and their values for the new record

Example

$module = 'Accounts';
$record = array(
    'name' => 'Test Account',
    'account_type' => 'Customer'
);
$SugarAPI = new \SugarAPI\SDK\SugarAPI($server,$creds);
$SugarAPI->login();
$SugarAPI->createRecord($module)->execute($record);

getRecord()

Retrieve a record from a module by its ID.
Utilizes the <module>/:record - GET API Endpoint

Class

SugarAPI\SDK\Endpoint\GET\ModuleRecord

Arguments

Name Type Description
$module string The Sugar module of the record
$id string The ID of the record you wish to retrieve

Example

$module = 'Accounts';
$id = '12345'
$SugarAPI = new \SugarAPI\SDK\SugarAPI();
$SugarAPI->login();
$SugarAPI->getRecord($module,$id)->execute();

filterRecords()

Retrieve a list of module records, and filter those records using the Filter API.
Utilizes the <module>/filter - POST API Endpoint

Class

SugarAPI\SDK\Endpoint\POST\ModuleFilter

Arguments

Name Type Description
$module string The Sugar module you wish to retrieve records from

Execution

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

Example

$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);

updateRecord()

Update a specific record in a module.
Utilizes the <module>/:record - PUT API Endpoint

Class

SugarAPI\SDK\Endpoint\PUT\ModuleRecord

Arguments

Name Type Description
$module string The Sugar module you wish to update a record in
$id string The ID of the record

Execution

Name Type Description
$record mixed Could be an array or \StdClass Object that defines the record attributes that should be updated

Example

$module = 'Accounts';
$id = '12345';
$record = array(
    'name' => 'Test updated'
);
$SugarAPI = new \SugarAPI\SDK\SugarAPI($server,$creds);
$SugarAPI->login();
$SugarAPI->updateRecord($module,$id)->execute($record);

deleteRecord()

Delete a specific record in a module.
Utilizes the <module>/:record - DELETE API Endpoint

Class

SugarAPI\SDK\Endpoint\DELETE\ModuleRecord

Arguments

Name Type Description
$module string The Sugar module you wish to delete a record in
$id string The ID of the record

Example

$module = 'Accounts';
$id = '12345';
$SugarAPI = new \SugarAPI\SDK\SugarAPI($server,$creds);
$SugarAPI->login();
$SugarAPI->deleteRecord($module,$id)->execute();

Authentication

oauth2Token()

Login to Sugar REST API and retrieve an OAuth 2.0 Access Token.
Utilizes the oauth2/token - POST API Endpoint

Class

SugarAPI\SDK\Endpoint\POST\OAuth2Token

Execution

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.

Example

$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);

oauth2Refresh()

Refresh an OAuth 2.0 authentication token for the Sugar REST API.
Utilizes the oauth2/token - POST API Endpoint.

Class

SugarAPI\SDK\Endpoint\POST\RefreshToken

Execution

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.

Example

$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();

oauth2Logout()

Logout of the Sugar REST API.
Utilizes the oauth2/logout - POST API Endpoint

Class

SugarAPI\SDK\Endpoint\POST\OAuth2Logout

Example

$SugarAPI = new \SugarAPI\SDK\SugarAPI($server,$creds);
$SugarAPI->login();
$SugarAPI->oauth2Logout()->execute();

User

me()

Gets the Current User.
Utilizes the me/ - GET API Endpoint

Class

SugarAPI\SDK\Endpoint\GET\Me

Example

$SugarAPI = new \SugarAPI\SDK\SugarAPI($server,$creds);
$SugarAPI->login();
$SugarAPI->me()->execute();

Relationships

createRelated()

Create a related record and link it to a module.
Utilizes the <module>/:record/link/:relationship - POST API Endpoint

Class

SugarAPI\SDK\Endpoint\POST\ModuleRecordRelationship

Arguments

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

Execution

Name Type Description
$record mixed Could be an array or \StdClass Object that defines the record attributes that should be created

Example

$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);

filterRelated()

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

Class

SugarAPI\SDK\Endpoint\GET\ModuleRecordRelationship

Arguments

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

Execution

Name Type Description
$filterArgs array An associative array of the filter arguments used to alter the result set

Example

$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);

getRelated()

Retrieve a record, related to a particular module's record.
Utilizes the <module>/:record/link/:relationship/:record_id - GET API Endpoint

Class

SugarAPI\SDK\Endpoint\GET\ModuleRecordLinkRecord

Arguments

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

Example

$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();

linkRecords()

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

Class

SugarAPI\SDK\Endpoint\POST\ModuleRecordLinkRecord

Arguments

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

Example

$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();

unlinkRecords()

Unlink the relationship between two records.
Utilizes the <module>/:record/link/:relationship/:record_id - DELETE API Endpoint

Class

SugarAPI\SDK\Endpoint\DELETE\ModuleRecordLinkRecord

Arguments

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

Example

$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();

Global Search

search()

Search all modules of the system for a particular criteria.
Utilizes the search - GET API Endpoint

Class

SugarAPI\SDK\Endpoint\GET\Search

Execution

Name Type Description
$searchArgs array An associative array with the Search arguments

Example

$searchArgs = array(
    'max_num' => 100,
    'offset' => 0,
    'q' => 'test'
);
$SugarAPI = new \SugarAPI\SDK\SugarAPI($server,$creds);
$SugarAPI->login();
$SugarAPI->search()->execute($searchArgs);

Bulk API

bulk()

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

Class

SugarAPI\SDK\Endpoint\POST\Bulk

Execution

Name Type Description
$endpoints array An array of Endpoint Objects

Example

$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
));

File Manipulation

attachFile()

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

Class

SugarAPI\SDK\Endpoint\POST\ModuleRecordFileField

Arguments

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

Execution

Name Type Description
$file string The path of the file to be uploaded

Example

$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);

getAttachment()

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

Class

SugarAPI\SDK\Endpoint\GET\ModuleRecordFileField

Arguments

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

Execution

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.

Example

$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();

deleteFile()

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

Class

SugarAPI\SDK\Endpoint\DELETE\ModuleRecordFileField

Arguments

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

Example

$module = 'Notes';
$id = '12345';
$file_field = 'filename';
$SugarAPI = new \SugarAPI\SDK\SugarAPI($server,$creds);
$SugarAPI->login();
$SugarAPI->deleteFile($module,$id,$file_field)->execute();

Other Methods

favorite()

Mark a module record as a favorite.
Utilizes the <module>/:record/favorite - PUT API Endpoint

Class

SugarAPI\SDK\Endpoint\PUT\ModuleRecordFavorite

Arguments

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

Example

$module = 'Accounts';
$id = '12345';
$SugarAPI = new \SugarAPI\SDK\SugarAPI($server,$creds);
$SugarAPI->login();
$SugarAPI->favorite($module,$id)->execute();

unfavortie()

Unmark a module record as a favorite.
Utilizes the <module>/:record/favorite - DELETE API Endpoint

Class

SugarAPI\SDK\Endpoint\DELETE\ModuleRecordFavorite

Arguments

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

Example

$module = 'Accounts';
$id = '12345';
$SugarAPI = new \SugarAPI\SDK\SugarAPI($server,$creds);
$SugarAPI->login();
$SugarAPI->unfavorite($module,$id)->execute();

ping()

Ping the Sugar REST API.
Utilizes the ping - GET API Endpoint

Class

SugarAPI\SDK\Endpoint\GET\Ping

Example

$SugarAPI = new \SugarAPI\SDK\SugarAPI($server,$creds);
$SugarAPI->login();
$SugarAPI->ping()->execute();