Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@betobaz
Last active December 13, 2016 04:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save betobaz/10001231 to your computer and use it in GitHub Desktop.
Save betobaz/10001231 to your computer and use it in GitHub Desktop.
User Custom Api
<?php
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:
* http://www.sugarcrm.com/master-subscription-agreement
*
* 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 users.id = ear.bean_id", array('alias' => 'users'));
$q->where()
->in("email_addresses.email_address", $emailAddresses)
->equals("ear.primary_address", "1");
$q->select->field("ear.bean_id");
$q->select->fieldRaw("users.user_name");
$email_rows = $q->execute();
$users['users'] = $email_rows;
return $users;
}
}
@betobaz
Copy link
Author

betobaz commented Apr 6, 2014

Url: rest/v10/Users/filter/email?email_addresses=["example1@example.com","example2@example.com"]

@brakon
Copy link

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: https://gist.github.com/brakon/5e3b64099d0fe98894eccce4d570a660

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