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