REST API v2 issue with suitecrm7.13 and php8

I’m migrating a SuiteCRM instance to a new server. Everything is pretty much the same except for the PHP version which is php8 on the new server and PHP 7.4 on the older one.

The problem is every time I call a REST Api function, I have the following error in the apache logs:

[Wed Jan 11 07:30:39.220385 2023] [php:error] [pid 2471] [client ***************] PHP Fatal error: Uncaught Error: Unknown named parameter $application_name in /var/www/SuiteCRM/service/core/REST/SugarRestJSON.php:94\nStack trace:\n#0 /var/www/SuiteCRM/service/core/SugarRestService.php(136): SugarRestJSON->serve()\n#1 /var/www/SuiteCRM/service/core/webservice.php(70): SugarRestService->serve()\n#2 /var/www/SuiteCRM/service/v4/rest.php(56): require_once(’…’)\n#3 {main}\n thrown in /var/www/SuiteCRM/service/core/REST/SugarRestJSON.php on line 94
[Wed Jan 11 07:30:39.405727 2023] [php:error] [pid 2473] [client ***************]] PHP Fatal error: Uncaught Error: Unknown named parameter $favorite in /var/www/SuiteCRM/service/core/REST/SugarRestJSON.php:94\nStack trace:\n#0 /var/www/SuiteCRM/service/core/SugarRestService.php(136): SugarRestJSON->serve()\n#1 /var/www/SuiteCRM/service/core/webservice.php(70): SugarRestService->serve()\n#2 /var/www/SuiteCRM/service/v4/rest.php(56): require_once(’…’)\n#3 {main}\n thrown in /var/www/SuiteCRM/service/core/REST/SugarRestJSON.php on line 94

The SuiteCRM logs do not report anything in particular.

Putting aside the PHP version, the code and database is the same.

Thanks

Exactly which PHP 8 is this? 8.0?

Yes, php8.0.

From the compatibility matrix (Compatibility Matrix :: SuiteCRM Documentation), suitecrm 7.13 supports PHP 7.4 and 8.0.

Thanks,

Any way, if you can try running it with PHP 7.4 and the error goes away, it could be an interesting diagnostic to see if this is a PHP version problem or not.

It seems the problem is with function call_user_func_array that had a major change in PHP 8.

Switching back to PHP 7.4 fixed the issue.

Hi @pgr

We are facing same issue we are on php 8.0, SuiteCRM 7.13 & Rest API v4_1 doesnt work.But we have few systems connected with our CRM.

Is there any hotfix for this issue?

Thanks in advance for your help.

Regards,
Sravani

Hi,
if you get the same error (Uncaught Error: Unknown named parameter $application_name) and you can’t downgrade php:

  • file /service/core/REST/SugarRestJSON.php
  • roughly line 94: look for the line $data = $json->decode($json_data);
  • add these lines directly after the found line:
if(array_key_exists('application_name', $data)){
 unset($data['application_name'];
}

this is just a fast workaround, it solved a login issue I had in a sandbox system, but I didn’t test anything further than that. Maybe there is also an approved fix already on github.

Hi @crmspace Thank you for responding , I tried your solution but i am unable to retrieve session id via Rest API v4_1

I had to manually enter the code here, and I missed a bracket:

if(array_key_exists('application_name', $data)){
 unset($data['application_name']);
}

Hi @crmspace Missed your previous response , Yes I have added correct bracket but still there is no response from login method.

@crmspace / @pgr kindly suggest if i’m missing anything

I believe that in your REST call, the three parameter names should be
user_auth
application
and
name_value_list

these are named parameters of the REST login function and my guess is that application_name does not work with PHP 8 due to a change in call_user_func_array

Hi @blqt , Thank you - I tried removing application_name param still it doesnt work.

Can you help me with working code if you have already.

Thank you in advance for your help.

Regards,
Sravani

Can you check your PHP error log?

Hi @blqt ,

I have checked suitecrm.log , apache & php error log - I cant find any . Here’s the code i m using to retrieve the session id

<?php
$url = "{site_url}/service/v4_1/rest.php";
$username = "XXXX";
$password = "XXXX";

function call($method, $parameters, $url)
{
    ob_start();
    $curl_request = curl_init();

    curl_setopt($curl_request, CURLOPT_URL, $url);
    curl_setopt($curl_request, CURLOPT_POST, 1);
    curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
    curl_setopt($curl_request, CURLOPT_HEADER, 1);
    curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl_request, CURLOPT_FOLLOWLOCATION, 0);

    $jsonEncodedData = json_encode($parameters);

    $post = array(
        "method" => $method,
        "input_type" => "JSON",
        "response_type" => "JSON",
        "rest_data" => $jsonEncodedData
    );

    curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post);
    $result = curl_exec($curl_request);
    curl_close($curl_request);

    $result = explode("\r\n\r\n", $result, 2);
    $response = json_decode($result[1]);
    ob_end_flush();

    return $response;
}

//login -----------------------------------------
$login_parameters = array(
    "user_auth" => array(
        "user_name" => $username,
        "password" => md5($password) ,
        "version" => "1"
    ) ,
    "application_name" => "RestTest",
    "name_value_list" => array() ,
);

$login_result = call("login", $login_parameters, $url);
echo "<pre>";
print_r($login_result);

//get session id
$session_id = $login_result->id;
echo $session_id;

I’m surprised you don’t see anything in the PHP error log if it fails.
Can you try again after changing

“application_name” => “RestTest”,

to

“application” => “RestTest”,

hi @blqt , that doesnt work too :frowning:

That’s hard to help without seing the apache/php error log.
Also, are you sure the login/password are correct?

Are you sure you’re dealing with the same error message like the OP? My code snippet should remove the application_name from the transformed json which is causing that error. If you get the same message, try removing "application_name" => "RestTest", from your $login_parameters.

Watching! I just spent half a day trying to connect Mautic to SuiteCRM via API and couldn’t figure out the problem. I tried another working install of SuiteCRM to connect to and voila, no problems. Only difference is the installation is running 7.4. So I switched my new install from 8.0 to 7.4 and connected no problems. Both of these are test instances, so if I can help in any way troubleshoot the php8 problem. I’m happy to.