Custom api sugarcrm 8.0 not working

The function of my code is, i want it to capitalize the initial letters of the field firstname and last name when they click the Upper name button.

here's the code:


class UpperNameApi extends SugarApi
public function registerApiRest()
return array(
'UpperNameRequest' => array(
//request type
'reqType' => 'GET',

//endpoint path
'path' => array('Leads', 'UpperName'),

//endpoint variables
'pathVars' => array('module','record'),

//method to call
'method' => 'UpperNameMethod',

//short help string to be displayed in the help documentation
'shortHelp' => 'Example endpoint',

//long help to be displayed in the help documentation
'longHelp' => 'custom/clients/base/api/help/MyEndPoint_MyGetEndPoint_help.html',

* Method to be used for my MyEndpoint/GetExample endpoint
public function UpperNameMethod($api, $args)
if (isset($args['record']) && !empty($args['record'])) {
$bean = BeanFactory::getBean('Leads', $args['record']);

if (!empty($bean->id)) {
$first = $bean->first_name;
$first = ucwords($first);
$bean->first_name = $first;

$last = $bean->last_name;
$last = ucwords($last);
$bean->last_name = $last;

return 'success';

return 'failed';



When i click the "Upper name button" it doesn't work:

i also tried using postman but this showed up: "error_message": "Could not find a route with 3 elements"


ive made another request in postman with this values but it shows: "A parameter in your request was invalid."



  • Good morning Karl,

    you have a problem with how you are defining your path and pathVars.

    Whenever you get a message like "Could not find a route with 3 elements" it is telling you that you are passing 3 elements, in your case "Leads" "UpperName" and the "module" (which I believe is the ID of the lead you want to process), but the end point is expecting a number of elements other than 3.


    in your case your endpoint expects only 2 elements 'Leads' and 'UpperName', what you really want is 'Leads','UpperName', and the ID of the record you want to process.

    So instead of:

    //endpoint path
    'path' => array('Leads', 'UpperName'),

    //endpoint variables
    'pathVars' => array('module','record'),


    //endpoint path
    'path' => array('Leads', 'UpperName','?'),

    //endpoint variables
    'pathVars' => array('','', 'record'),

    Notice that the third element in your path, the ?, is your variable placeholder, and the third element in your pathVars is the name that will be associated with that variable in your $args. So $args['record'] is the ID that you are passing.

    Now your API has three elements as does your call:


    where record_id is the id of the lead you are wanting to update.





  • One more thought, instead of giving them an action to capitalize names, why not do it at data entry?

    I would use a before save logic hook, you can restrict it to new records only so that if someone really intends to have a lower case letter like some last names, "van Gogh" for example, they can edit the name after the Lead was generated and save it with the lower case letter. 


  • thanks francesca the problem has been solved.