Skip to content

Instantly share code, notes, and snippets.

// Now, let's add a new Accounts record
$parameters = array(
'session' => $sessionId,
'module' => 'Accounts',
'name_value_list' => array(
array('name' => 'name', 'value' => 'New Account'),
array('name' => 'description', 'value' => 'This is an account created from a REST web services call'),
),
);
$json = json_encode($parameters);
@jmertic
jmertic / gist:6584335
Created September 16, 2013 18:11
Exporting a report as a PDF using the new RESTful API in Sugar 6.7 and later.
<?php
// specify the REST web service to interact with
$url = 'https://localhost/~jmertic/sugar7/ent/sugarcrm/rest/v10';
// And admin username/password
$username = 'will';
$password = 'will';
// And the report_id you wish to export
@jmertic
jmertic / gist:5847575
Last active May 10, 2016 12:48
Sample Node.js script using Restler for connecting to the new RESTful SugarCRM REST API in 6.7 and later.
var sys = require('util'),
rest = require('restler');
var baseurl = "<<instance URL>>/rest/v10"
// get oAuth token
var jsonData = {"grant_type":"password","username":"<<username>>","password":"<<password>>","client_id":"sugar"};
rest.postJson(baseurl+'/oauth2/token', jsonData).on('2XX', function(data) {
if ( data.error ) {
sys.puts("Error: " + data.error_message);
...abbreviated
<div class="dropdown-menu scroll pull-right">
<ul role="menu">
<li class="profileactions-profile"><a href="{{profileUrl}}">{{str "LBL_PROFILE"}}</a></li>
<li class="profileactions-employees"><a href="{{employeesUrl}}">{{str "LBL_EMPLOYEES"}}</a></li>
{{#if showAdmin}}
<li class="administration"><a href="#Administration">{{str "LBL_ADMIN"}}</a></li>
{{/if}}
<li class="profileactions-about"><a href="#bwc/index.php?module=Home&action=About">{{str "LNK_ABOUT"}}</a></li>
<li class="profileactions-logout"><a href="#logout/?clear=1">{{str "LBL_LOGOUT"}}</a></li>
@jmertic
jmertic / ReportsExportCsvApi.php
Created November 7, 2013 02:40
Example of extending the REST API in Sugar 7. This example overrides the OOTB Reports export functionality to enable CSV exports. To use this, drop the file in the custom/Reports/clients/base/api/ directory.
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*
* Copyright (c) 2013, John Mertic
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
<?php
function link_record_beans($bean1, $bean2){
$m1 = $bean1->module_dir;
$m2 = $bean2->module_dir;
$rel=getRelationshipByModules($m1, $m2); //see link to previous post for this function
if($rel !== FALSE){
if($rel[1] == $m1){
$class = $bean1->object_name;
$id = $bean1->id;
<?php
public function exportSanitize($value, $vardef, $focus, $row=array()) {
return $this->formatField($value, $vardef);
}
<?php
$configurator = new Configurator();
if (!isset($configurator->config['test_key1'])) {
$configurator->config['test_key1'] = 'test_value1';
}
$configurator->handleOverride();
<?php
//set up options array
$options = array(
"location" => 'https://site14/sugar6/soap.php',
"uri" => 'http://www.sugarcrm.com/sugarcrm',
"trace" => 1
);
//user authentication array
$user_auth = array(
@jmertic
jmertic / gist:6584226
Created September 16, 2013 18:02
Exporting a report as a PDF via Web Services
<?php
// specify the REST web service to interact with
$url = '<<your sugar instance URL>>/service/v4_1/rest.php';
// And admin username/password
$username = '<<username>>';
$password = '<<password>>';
// And the report_id you wish to export