Hello @pgr
Thanks for replying.
I have created a custom API file public/legacy/custom/service/mob_v4/SugarWebServiceImplcustom_v4.php
with this API function;
function custom_setEntry($session, $user_id, $module_name, $nameValueList) {
$error = new SoapError();
if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) {
$GLOBALS['log']->info('End: SugarWebServiceImplmob_v4->mob_setUserProfile.');
return false;
}
global $sugar_config;
require_once('service/v4_1/SugarWebServiceImplv4_1.php');
$objModule = BeanFactory::getBean($module_name);
$objUsers = BeanFactory::getBean('Users', $user_id);
$field_defination = $objModule->getFieldDefinitions();
$user_dec_sep = $objUsers->getPreference('dec_sep');
$user_num_grp_sep = $objUsers->getPreference('num_grp_sep');
$currencyDigits = $objUsers->getPreference('default_currency_significant_digits');
foreach ($nameValueList as $keynumber => $NameValueArray) {
if ($field_defination[$NameValueArray['name']]['type'] == 'currency' || $field_defination[$NameValueArray['name']]['type'] == 'decimal' || $field_defination[$NameValueArray['name']]['type'] == 'float') {
$actualValue = number_format($NameValueArray['value'], $currencyDigits, $user_dec_sep, $user_num_grp_sep);
$nameValueList[$keynumber]['value'] = $actualValue;
}
}
$objV4_1 = new SugarWebServiceImplv4_1();
$setEntryResponse = $objV4_1->set_entry($session, $module_name, $nameValueList);
$getEntryResponse = $objV4_1->get_entry($session, $module_name, $setEntryResponse['id'], array(), array());
$ReturnResponse['id'] = $setEntryResponse['id'];
foreach ($getEntryResponse['entry_list'] as $response) {
foreach ($response as $setEntyResponse) {
if ($setEntyResponse != 'id' && $setEntyResponse != 'module_name') {
$ReturnResponse['entry_list'] = $setEntyResponse;
}
}
}
if ($module_name == 'AOS_Products' || $module_name == 'Mob_followups') {
$moduleObj = BeanFactory::getBean($module_name, $setEntryResponse['id']);
if ($module_name == 'AOS_Products') {
$moduleObj->product_image = $sugar_config['site_url'] . '/upload/' . $filename;
} else {
$moduleObj->filename = $filename;
$filename = $setEntryResponse['id'];
}
$moduleObj->save();
$myfile = fopen('upload/' . $filename, 'w');
$actualContent = base64_decode($imageContent);
fwrite($myfile, $actualContent);
fclose($myfile);
$ReturnResponse['imageContent'] = $imageContent;
}
return $ReturnResponse;
}
Also, I have created one API request in POSTMAN APIs with this form data:
method:custom_setEntry
input_type:JSON
response_type:JSON
rest_data:{"session":"cl0ki83cnb0r8dd3oqr549aams","user_id":"1","module_name":"Calls_Reschedule","name_value_list":[{"name":"call_id","value":"3e372359-ea80-10f6-a7d5-6576fab952ae"},{"name":"reason","value":"In a Meeting"}],"recordId":"3e372359-ea80-10f6-a7d5-6576fab952ae"}
Apart from this, I have debugged this file code: public/legacy/service/core/REST/SugarRestJSON.php
public function serve(){
$GLOBALS['log']->info('Begin: SugarRestJSON->serve');
$json_data = !empty($_REQUEST['rest_data'])? $GLOBALS['RAW_REQUEST']['rest_data']: '';
print_r($json_data);exit;
if(empty($_REQUEST['method']) || !method_exists($this->implementation, $_REQUEST['method'])){
$er = new SoapError();
$er->set_error('invalid_call');
$this->fault($er);
}else{
$method = $_REQUEST['method'];
$json = getJSONObj();
$data = $json->decode($json_data);
if(!is_array($data))$data = array($data);
if (!isset($data['application_name']) && isset($data['application'])){
$data['application_name'] = $data['application'];
}
$res = call_user_func_array(array( $this->implementation, $method),$data);
$GLOBALS['log']->info('End: SugarRestJSON->serve');
return $res;
} // else
} // fn
But when I print the $res
every time I get 500 internal server errors in POSTMAN APIs and get an error:
Fatal error: Uncaught Error: Unknown named parameter $name_value_list in /var/www/html/crm/crm84_v2_1/public/legacy/service/core/REST/SugarRestJSON.php:106
Stack trace:
#0 /var/www/html/crm/crm84_v2_1/public/legacy/service/core/SugarRestService.php(137): SugarRestJSON->serve()
#1 /var/www/html/crm/crm84_v2_1/public/legacy/service/core/webservice.php(70): SugarRestService->serve()
#2 /var/www/html/crm/crm84_v2_1/public/legacy/custom/service/mob_v4/rest.php(15): require_once('...')
#3 {main}
thrown in /var/www/html/crm/crm84_v2_1/public/legacy/service/core/REST/SugarRestJSON.php on line 106
and when I call custom_setEntry() directly via POSTMAN, it doesn’t call the function and gives a 500 error every time. and no error is coming in the php log or suitecrm log.
For reference, I checked these links but didn’t find a solution.
- Rest API v4_1 is not working with my new setup i.e. php 8.0, SuiteCRM 7.13
- REST API v2 issue with suitecrm7.13 and php8