Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
User Custom Api
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
* By installing or using this file, you are confirming on behalf of the entity
* subscribed to the SugarCRM Inc. product ("Company") that Company is bound by
* the SugarCRM Inc. Master Subscription Agreement (“MSA”), which is viewable at:
* If Company is not bound by the MSA, then by installing or using this file
* you are agreeing unconditionally that Company will be bound by the MSA and
* certifying that you have authority to bind Company accordingly.
* Copyright (C) 2004-2014 SugarCRM Inc. All rights reserved.
require_once 'include/api/SugarApi.php';
class UserCustomApi extends SugarApi
public function registerApiRest()
return array(
'retrive_by_emails' => array(
'reqType' => 'GET',
'path' => array('Users','filter','email',),
'pathVars' => array(),
'method' => 'retriveUsersByEmailAddress',
'shortHelp' => 'Retrieve Users by email addresses',
'longHelp' => '',
public function retriveUsersByEmailAddress($api, $args)
$users = array();
//$users['args'] = $args;
$emailAddresses = explode(",",preg_replace('/[\[\]\"]/', '', $args['email_addresses']));
$email = BeanFactory::getBean('EmailAddresses');
$q = $email->getEmailsQuery('Users');
$q->joinRaw("JOIN users ON users.deleted = 0 and = ear.bean_id", array('alias' => 'users'));
->in("email_addresses.email_address", $emailAddresses)
->equals("ear.primary_address", "1");
$email_rows = $q->execute();
$users['users'] = $email_rows;
return $users;

This comment has been minimized.

Copy link
Owner Author

@betobaz betobaz commented Apr 6, 2014

Url: rest/v10/Users/filter/email?email_addresses=["",""]


This comment has been minimized.

Copy link

@brakon brakon commented Dec 13, 2016

The class name should be changed to CustomUserAPI and the filename also for it to work on Sugar 7

Here is the modification:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment