AnsweredAssumed Answered

Custom api sugarcrm 8.0 not working

Question asked by karl el escobar on Feb 18, 2019
Latest reply on Feb 19, 2019 by karl el escobar

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:

 

<?php

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;
$bean->save();
}

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"

 

 

UPDATED

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

UPDATED AGAIN

PROBLEM FIXED.

Outcomes