SlideShare a Scribd company logo
Using the SugarCRM
     REST API
About the Speaker
                         Asa
                         Kusuma
• Web Developer at Milsoft Utility Solutions
• Junior at Abilene Christian University
• Twitter: asakusuma
• asakusuma.com
What is a REST API?
• Web service
 • Allow external access to data
 • Some protocol for transferring data
• Representational State Transfer
• Transfer an object’s “state” across apps
• Encode with JSON, send using HTTPS
REST vs. SOAP
• REST               photo by superbomba




 • JSON
 • Less overhead
• SOAP
 • XML
 • More overhead
Web Services:
What’s the Big Deal?
photo by gerlos




                      www.photographyicon.com




Bridge apps with data
CRM needs external data

External apps need CRM data
Our Needs at Milsoft
•   Support Portal                photo by eBeam




    • Customers create and view cases
    • Add notes with attachments
• Customers update company data
• Give customers limited data access
Using the SugarCRM REST API
End Goal:
Build a web app that
talks with SugarCRM
The End Goal Expanded
•   CRUD capability           photo by eBeam




•   PHP web app

    •   cURL Library

    •   JSON

    •   Wrapper class

•   Security            photo by Sprengben
The Big Picture
PHP App     SugarCRM

Model         Data



             REST API
The Big Picture
  PHP App      SugarCRM

   Model         Data



REST Wrapper
                REST API
    Class
The Big Picture
  PHP App             SugarCRM

   Model                Data

               API
               Call
REST Wrapper
                      REST API
    Class
Get the code

asakusuma.com/sugarcon/2011/
Ideal Code Example
                                           photo by eBeam
$sugar = new SugarREST();

$module = “Cases”;

$fields = array(‘id’,‘name’,‘status’);

$records = $sugar->get($module,$fields);

foreach($records as $record) {

    echo $record[‘name’];

}
But first, some REST API basics
What’s an API Call?
• Request to create, read, update, or delete
• API responds with data or confirmation
• 3 Parts
 • Method = Specify what to do
 • Arguments = Specify details
 • API Response = What happened
API Call Example

• Create a new Contact
• Method = set_entry
• Arguments = New Contact data
• Response = ID of newly created Contact
JSON Primer
array(
                           photo by eBeam


    ‘name’ => ‘Robert’,

    ‘children’ => array(

        ‘Chris’,

        ‘Anne’,

        ‘Bob’

    )

)
JSON Primer (cont.)
{
                       photo by eBeam


    “name”:“Robert”,

    “children” : {

        0:“Chris”,

        1:“Anne”,

        2:“Bob”

    }

}
JSON Primer (cont.)
                                  photo by eBeam




$my_array = array(1,2,3);

$my_json_str = json_encode($my_array);

$my_array = json_decode($my_json_string);

//$my_array remains unchanged
Making REST API Calls

• https://mysite.com/sugarcrm/service/v2/rest.php
• Method name
• Arguments (JSON)
• Input type
• Response type
Example POST Data

method=login&
input_type=json&
response_type=json&
rest_data={"name": “value”}
Implemented in PHP
$ch = curl_init();


curl_setopt($ch, CURLOPT_URL, $rest_api_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);


curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);


$output = json_decode(curl_exec($ch));
Authentication
1. Make “Login” REST call                photo by eBeam




2. Receive session ID

3. Use session ID to authenticate other calls

4. Make “Logout” REST call with session ID

5. Use HTTPS
Example: Modify Contact
Modify Contact (cont.)
$arguments = array(
     'session' => $session_id,
	 'module_name' => 'Contacts',
	 'name_value_list' => array(
          'id'=>'9hg5a93a-2dfdf-d6pe-1oq4-cjqic4mxok',
          'title'=>'REST API Guy'
     )
);
Modify Contact (cont.)
$post_data   = "method=set_entry&";
$post_data .= "input_type=json&";
$post_data .= "response_type=json&";
$post_data .= "rest_data=".json_encode($arguments);
	 	
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $rest_api_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$output = json_decode(curl_exec($ch));
REST Wrapper Class
1. Download: asakusuma.com/sugarcon/2011/code
  • example.php
  • sugar_rest.php
  • README.markdown
2. Read the README (it’s there for a reason)
3. Configure sugar_rest.php
4. Run the example
Important Functions
set() is for both create and update operations

set($module, $fields, $options);
get($module, $fields, $options);
get_with_related($module, $fields,
$options);
Note Functions
• set_note_attachment()
• get_note_attachment()
• Use binary data
• Arguments are a little complicated
• Use documentation in the README
Things to Keep in Mind

• You must specify a query LIMIT
• Different output format for get() and
  get_with_related()
• Wrapper doesn’t include delete
• Use HTTPS
Security
                                photo by maistora




•   Protect your data

•   Weakest link

•   REST API = liability

•   Use caution when
    mapping URL to data
photo by gerlos




Leverage your data.
                       www.photographyicon.com




Connect your apps.
Presentation + Code at
asakusuma.com/sugarcon/2011
   Questions? Comments?
  asa.kusuma@milsoft.com
     Twitter: asakusuma
       Official Docs at
  developers.sugarcrm.com

More Related Content

PDF
Prompt Engineering for AI and ML Technical Product Managers - 2023-08-21 00.5...
PDF
Encimera Teka IR 531
PDF
딥러닝 기반의 자연어처리 최근 연구 동향
PDF
Main Idea (Mama)
PDF
Easy Integration of your external systems with SugarCRM
PDF
SugarCRM Integration
PDF
Practical JavaScript Promises
PDF
How to Build a Java client for SugarCRM
Prompt Engineering for AI and ML Technical Product Managers - 2023-08-21 00.5...
Encimera Teka IR 531
딥러닝 기반의 자연어처리 최근 연구 동향
Main Idea (Mama)
Easy Integration of your external systems with SugarCRM
SugarCRM Integration
Practical JavaScript Promises
How to Build a Java client for SugarCRM

Viewers also liked (14)

PDF
Sugar U: Session 4: Using SugarCRM as a Project Development Platform
PDF
OKRy - co to jest i jak wdrożyć w organizacji
PPT
開発プラットフォームとしてのSugarCRM
PDF
Prioritizing Portfolio Backlog to Maximize Value Steve Mayner Agile Asia 2016
PPTX
Connecting the Clouds to Drive the Customer Journey
PPTX
Getting the Most Out of Microsoft Dynamics CRM Integrations
DOCX
Group Writing Sample - Business Proposal
PPTX
Presentation
PDF
Mi carta a los ciudadanos xxiii 15ene2014
PDF
Repercusión mediática Football Transfer Review 2011
PDF
Ley 962 ley de accesibilidad
PDF
Claudio Adrian Natoli - Periodismo digital
Sugar U: Session 4: Using SugarCRM as a Project Development Platform
OKRy - co to jest i jak wdrożyć w organizacji
開発プラットフォームとしてのSugarCRM
Prioritizing Portfolio Backlog to Maximize Value Steve Mayner Agile Asia 2016
Connecting the Clouds to Drive the Customer Journey
Getting the Most Out of Microsoft Dynamics CRM Integrations
Group Writing Sample - Business Proposal
Presentation
Mi carta a los ciudadanos xxiii 15ene2014
Repercusión mediática Football Transfer Review 2011
Ley 962 ley de accesibilidad
Claudio Adrian Natoli - Periodismo digital
Ad

Similar to Using the SugarCRM REST API (20)

PDF
Web Apps for the Masses
PPTX
Crafting Evolvable Api Responses
PPTX
MongoDB.local Dallas 2019: Pissing Off IT and Delivery: A Tale of 2 ODS's
PDF
RESTful API-centric Universe
PDF
Building APIs in an easy way using API Platform
PPTX
API-first development
PPTX
REST API for your WP7 App
PDF
ApacheCon 2005
PDF
Web Services PHP Tutorial
PDF
Painless Persistence in a Disconnected World
PDF
From System Engineer to Gopher
PDF
Rethinking Syncing at AltConf 2019
PPTX
Data-Analytics using python (Module 4).pptx
PPTX
Austin Day of Rest - Introduction
PPTX
PPTX
Rest with Java EE 6 , Security , Backbone.js
KEY
WordPress APIs
PDF
I Love APIs Europe 2015: Developer Sessions
PDF
Ember Data and JSON API
PDF
Consuming RESTful Web services in PHP
Web Apps for the Masses
Crafting Evolvable Api Responses
MongoDB.local Dallas 2019: Pissing Off IT and Delivery: A Tale of 2 ODS's
RESTful API-centric Universe
Building APIs in an easy way using API Platform
API-first development
REST API for your WP7 App
ApacheCon 2005
Web Services PHP Tutorial
Painless Persistence in a Disconnected World
From System Engineer to Gopher
Rethinking Syncing at AltConf 2019
Data-Analytics using python (Module 4).pptx
Austin Day of Rest - Introduction
Rest with Java EE 6 , Security , Backbone.js
WordPress APIs
I Love APIs Europe 2015: Developer Sessions
Ember Data and JSON API
Consuming RESTful Web services in PHP
Ad

Recently uploaded (20)

PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Approach and Philosophy of On baking technology
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Unlocking AI with Model Context Protocol (MCP)
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Approach and Philosophy of On baking technology
NewMind AI Weekly Chronicles - August'25 Week I
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Advanced methodologies resolving dimensionality complications for autism neur...
MYSQL Presentation for SQL database connectivity
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Chapter 3 Spatial Domain Image Processing.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Building Integrated photovoltaic BIPV_UPV.pdf

Using the SugarCRM REST API

  • 2. About the Speaker Asa Kusuma • Web Developer at Milsoft Utility Solutions • Junior at Abilene Christian University • Twitter: asakusuma • asakusuma.com
  • 3. What is a REST API? • Web service • Allow external access to data • Some protocol for transferring data • Representational State Transfer • Transfer an object’s “state” across apps • Encode with JSON, send using HTTPS
  • 4. REST vs. SOAP • REST photo by superbomba • JSON • Less overhead • SOAP • XML • More overhead
  • 6. photo by gerlos www.photographyicon.com Bridge apps with data
  • 7. CRM needs external data External apps need CRM data
  • 8. Our Needs at Milsoft • Support Portal photo by eBeam • Customers create and view cases • Add notes with attachments • Customers update company data • Give customers limited data access
  • 10. End Goal: Build a web app that talks with SugarCRM
  • 11. The End Goal Expanded • CRUD capability photo by eBeam • PHP web app • cURL Library • JSON • Wrapper class • Security photo by Sprengben
  • 12. The Big Picture PHP App SugarCRM Model Data REST API
  • 13. The Big Picture PHP App SugarCRM Model Data REST Wrapper REST API Class
  • 14. The Big Picture PHP App SugarCRM Model Data API Call REST Wrapper REST API Class
  • 16. Ideal Code Example photo by eBeam $sugar = new SugarREST(); $module = “Cases”; $fields = array(‘id’,‘name’,‘status’); $records = $sugar->get($module,$fields); foreach($records as $record) { echo $record[‘name’]; }
  • 17. But first, some REST API basics
  • 18. What’s an API Call? • Request to create, read, update, or delete • API responds with data or confirmation • 3 Parts • Method = Specify what to do • Arguments = Specify details • API Response = What happened
  • 19. API Call Example • Create a new Contact • Method = set_entry • Arguments = New Contact data • Response = ID of newly created Contact
  • 20. JSON Primer array( photo by eBeam ‘name’ => ‘Robert’, ‘children’ => array( ‘Chris’, ‘Anne’, ‘Bob’ ) )
  • 21. JSON Primer (cont.) { photo by eBeam “name”:“Robert”, “children” : { 0:“Chris”, 1:“Anne”, 2:“Bob” } }
  • 22. JSON Primer (cont.) photo by eBeam $my_array = array(1,2,3); $my_json_str = json_encode($my_array); $my_array = json_decode($my_json_string); //$my_array remains unchanged
  • 23. Making REST API Calls • https://mysite.com/sugarcrm/service/v2/rest.php • Method name • Arguments (JSON) • Input type • Response type
  • 25. Implemented in PHP $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $rest_api_url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); $output = json_decode(curl_exec($ch));
  • 26. Authentication 1. Make “Login” REST call photo by eBeam 2. Receive session ID 3. Use session ID to authenticate other calls 4. Make “Logout” REST call with session ID 5. Use HTTPS
  • 28. Modify Contact (cont.) $arguments = array( 'session' => $session_id, 'module_name' => 'Contacts', 'name_value_list' => array( 'id'=>'9hg5a93a-2dfdf-d6pe-1oq4-cjqic4mxok', 'title'=>'REST API Guy' ) );
  • 29. Modify Contact (cont.) $post_data = "method=set_entry&"; $post_data .= "input_type=json&"; $post_data .= "response_type=json&"; $post_data .= "rest_data=".json_encode($arguments); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $rest_api_url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); $output = json_decode(curl_exec($ch));
  • 30. REST Wrapper Class 1. Download: asakusuma.com/sugarcon/2011/code • example.php • sugar_rest.php • README.markdown 2. Read the README (it’s there for a reason) 3. Configure sugar_rest.php 4. Run the example
  • 31. Important Functions set() is for both create and update operations set($module, $fields, $options); get($module, $fields, $options); get_with_related($module, $fields, $options);
  • 32. Note Functions • set_note_attachment() • get_note_attachment() • Use binary data • Arguments are a little complicated • Use documentation in the README
  • 33. Things to Keep in Mind • You must specify a query LIMIT • Different output format for get() and get_with_related() • Wrapper doesn’t include delete • Use HTTPS
  • 34. Security photo by maistora • Protect your data • Weakest link • REST API = liability • Use caution when mapping URL to data
  • 35. photo by gerlos Leverage your data. www.photographyicon.com Connect your apps.
  • 36. Presentation + Code at asakusuma.com/sugarcon/2011 Questions? Comments? asa.kusuma@milsoft.com Twitter: asakusuma Official Docs at developers.sugarcrm.com

Editor's Notes