Can someone please provide and example and result of an api call that get data from MySQl using beans?

Hello,

I've been given the task of creating  a custom endpoint for the api that reads data using sugar beans but I can't seem to get the beans to return anything other than a definition of the bean, null, or [].  Can someone please provide an example and the results so I can see if working? 

Best Regards

  James Palmisano

  • Hi James,

    We have documented an example about Extending Endpoints/#Example - Developer Guide.

    If you could share your code it would be better to identify why your end point returns empty array or null.

    Considering you are getting an record_id for Accounts in paths of registerApiRest() like;

    'path' => array('Accounts', '?'),
    'pathVars' => array('', 'record_id'),
    

    Then in your method you need to;

    /**
     * Method to be used for my MyEndpoint/GetExample endpoint
     */
    public function MyGetMethod($api, $args)
    {
        return BeanFactory::getBean('Accounts',$args['record_id'], array('disable_row_level_security' => true));  
    }
    

    There is another approach using SugarQuery - Developer Guide.

    /**
     * Method to be used for my MyEndpoint/GetExample endpoint
     */
    public function MyGetMethod($api, $args)
    {
        $query = new \SugarQuery();
        $query->from(BeanFactory::newBean("Accounts"), array('team_security' => false));
        $query->select(array('id','name'));
        $query->where()->equals('id', $args['record_id']);
        $query->limit(50);
        return $query->execute();
    }
    

    Hope these helps.

    Best Regards

    Tevfik Tümer

    Developer Support Engineer

  • I figured out that I was missing a require_once reference to the bean factory and that args['data'] is the argument that I send through the url not args. Once I had that development with beans became cake.  Thank you for the response Tevfik Tümer