Code Monkey home page Code Monkey logo

sugarcrm-rest-api-wrapper-class's Introduction

SugarCRM REST API Wrapper Class

by Asa Kusuma

http://www.asakusuma.com/

License: MIT

Contents

  1. About
  2. Installation
  3. Usage Example
  4. Notes
  5. get_note_attachment() Example
  6. set_note_attachment() Example

1.About

2.Installation

  1. Configure by setting the $rest_url, $username, and $password class variables in the sugar_rest.php class file. The username and password of any SugarCRM user should work. It's recommended that you create a new SugarCRM user account to be exclusively used for authenticating API calls.
  2. Just import the class with require("sugar_rest.php"); and code away!

3.Usage Example

require_once("sugar_rest.php");
$sugar = new Sugar_REST();
$results = $sugar->get("Accounts",array('id','name'));
print_r($results);

See example.php for another example.

4.Notes

  • The is_valid_id() function may need to modify for different versions of SugarCRM.
  • Different versions of SugarCRM have different ID formats.

5.get_note_attachment() Example

This example outputs the contents of a note's attachment, given the note ID. Assumes $note_id contains the ID of the note you wish to modify.

require_once("sugar_rest.php");
$sugar = new Sugar_REST();

$result = $sugar->get_note_attachment($note);
$filename = $result['note_attachment']['filename'];
$file = $result['note_attachment']['file'];

$file = base64_decode($file);
header("Cache-Control: no-cache private");
header("Content-Description: File Transfer");
header('Content-disposition: attachment; filename='.$filename);
header("Content-Type: application/vnd.ms-excel");
header("Content-Transfer-Encoding: binary");
header('Content-Length: '. strlen($file));
echo $file;
exit;

6.get_note_attachment() Example

This example illustrates how to set a note's attachment from an html form. Assumes $note_id contains the ID of the note you wish to modify.

HTML Code

<form method="post" action="example.php" enctype="multipart/form-data">
	<input name="note_file" type="file" />
	<input type="submit" value="Go" />
</form>

PHP Code (example.php)

require_once("sugar_rest.php");
$sugar = new Sugar_REST();
if ($_FILES["note_file"]["error"] > 0) {
	// Error: $_FILES["file"]["error"]
} else if(isset($_FILES['note_file']['tmp_name']) && $_FILES['note_file']['tmp_name']!="") {
	$handle = fopen($_FILES['note_file']['tmp_name'], "rb");
	$filename = $_FILES['note_file']['name'];
	$contents = fread($handle, filesize($_FILES['note_file']['tmp_name']));
	$binary = base64_encode($contents);
	$file_results = $sugar->set_note_attachment($note_id,$binary,$filename);
}

7.get_available_modules() Example

This example illustrates how to get the available modules in Sugar. All of them.
This is a handy function to use when building future proof sugarcrm plugins.

PHP Code (example.php)

require_once("sugar_rest.php");
$sugar = new Sugar_REST();
$modules = $sugar->get_available_modules();

BAM! Now loop through the array that was returned and stored in $modules. You could use this to display a dropdown in the admin panel that displays all modules a user would want to connect your sugarcrm plugin to.

sugarcrm-rest-api-wrapper-class's People

Contributors

asakusuma avatar chadhutchins avatar filiptepper avatar xtrimsky avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.