AnsweredAssumed Answered

API new endpoint

Question asked by Gustav Lindström on Feb 26, 2015
Latest reply on Feb 27, 2015 by Gustav Lindström
I've created the simplest possible api endpoint following the guide from the developer blog.

http://developer.sugarcrm.com/2014/03/10/sugarcrm-cookbook-adding-a-rest-endpoint-2/

'path' => array('Accounts', 'at_risk'),             
'pathVars' => array('Accounts', 'at_risk',

It returns a text string and It works fine.

 I then change the path and pathvar in to this

'path' => array('Accounts', 'at_risk','?'),             
'pathVars' => array('Accounts', 'at_risk', 'model_id'),

I the get error response {"error":"not_found","error_message":"Could not find record: at_risk in module: Accounts"} no matter if I add the varible in the call or not. It say's I can add wild cards. Am I doing it wrong?

This is what it looks like;

class AtRiskApi extends SugarApi{
    // This function is only called whenever the rest service cache file is deleted.
    // This shoud return an array of arrays that define how different paths map to different functions
    public function registerApiRest() {
        return array(
            'getAtRisk' => array(
                // What type of HTTP request to match against, we support GET/PUT/POST/DELETE
                'reqType' => 'GET',
                // This is the path you are hoping to match, it also accepts wildcards of ? and <module>
                'path' => array('Accounts', 'at_risk','?'),
                // These take elements from the path and use them to populate $args
                'pathVars' => array('Accounts', 'at_risk', 'model_id'),
                // This is the method name in this class that the url maps to
                'method' => 'getAtRisk',
                // The shortHelp is vital, without it you will not see your endpoint in the /help
                'shortHelp' => 'Lists at risk accounts in the system',
                // The longHelp points to an HTML file and will be there on /help for people to expand and show
                'longHelp' => '',
            ),
        );
    }
    
function getAtRisk($api, $args)
{
//return  $args['model_id'];
return 'hej';

}
}

Outcomes