How to retrieve or get bean in custom end point

This is the code that I have but I kept getting null as the REST response.

but when I use raw SQL query I am able to get the results that I needed. However i'd prefer to use the Bean module instead of doing sql query.

What am I doing wrong?

<?php

if(!defined('sugarEntry') || !sugarEntry) die('Not a Valid Entry Point!');

class SdcImportApi extends SugarApi

{

  public function registerApiRest()

  {

  return array(

  'SdcEndPoint' => array(

  'reqType' => 'GET',

  'noLoginRequired' => true,

  'path' => array('SdcEndPoint','GetExample', '?'),

  'pathVars' => array('','','contactId'),

  'method' => 'MyGetMethod'),

  );

  }

  public function MyGetMethod($api, $args)

  {

  $contact = BeanFactory::retrieveBean('contacts','f3dc0892-d081-8b8e-dce8-571a703a3593',array('disable_row_level_security' => true));

  return $contact;

  //global $db;

  //$query ="select * from contacts c join contacts_cstm cc on cc.id_c = c.id where c.id = 'f3dc0892-d081-8b8e-dce8-571a703a3593'";

  //$result = $db->query($query,true);

  //$row = $db->fetchByAssoc($result);

  //return $row;

  //return $args['contactId'];

  }

}

?>

Parents Reply
  • Hi Doddy,

    Ah, I can't believe I didn't catch that! You shouldn't need to require ./data/BeanFactory.php. If you wanted to have a no-auth endpoint and still use most Sugar core functionality, you would have to set a user as the current user. An example would be:

    global $current_user;

    if (empty($current_user) || empty($current_user->id)) {

        $current_user = new User();

        $current_user->getSystemUser(); // or any other user bean

    }

    This is very risky and you should be aware that it could lead to a security breach depending on what the endpoint is doing.

    If you want to pass an array of information, I would suggest making the endpoint's request type "POST":

    'reqType' => 'POST',

    Then you can pass any data you like in the request body. An example is:

    http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.7/Integration/Web_Services/v10/Example…

    If you did this post to your custom endpoints url, you would see name and email1 in the $args parameter of your method.

    Hope this helps!

    Kind regards,

    Jerry Clark

    Sr. Manager, Developer Support & Support Applications

Children