API v4.1 method login -> File not found

Hi, I am trying to send a login request to the demo environment but receiving an error 404 Not Found. It is running on version 7.13.0. I’ve tested the same request on the demo environment but version 8.2.2 and it works.

The request is:

https://demo.suiteondemand.com/service/v4_1/rest.php?method=login&input_type=JSON&response_type=JSON&rest_data={“user_auth”: {“user_name”: “will”, “password”: “18218139eec55d83cf82679934e5cd75”, “version”:“1” }, “application_name”: “test”}

Response:
Status 404 File not found.

Any help is appreciated, thanks!

I’m also trying to figure out how to use the API. It seems that examples are certainly lacking. I see PHP examples, but I’m using BASH, so they are only somewhat helpful.

Anyway, I can tell from the start that one of your issues is that you’re likely executing a GET request. It needs to be a POST request with your parameters in the body as ContentType: application/x-www-form-urlencoded. Start with that.

The second issue is that you need to MD5 the password e.g. md5sum <password_here> and send that instead of the raw password.

Good luck. I’ll post back if I can get it working.

I am able to the REST API with the following details

URL:
http://localhost/suitecrm/service/v4_1/rest.php (local)

Http Method:
POST

Posted Data:
{"method":"login","input_type":"JSON","response_type":"JSON","rest_data":"{\"user_auth\":{\"user_name\":\"admin\",\"password\":\"21232f297a57a5a743894a0e4a801fc3\"}}"}

PHP Code:

<?php

$url = 'http://localhost/suitecrm/service/v4_1/rest.php';

$curl = curl_init($url);

curl_setopt($curl, CURLOPT_POST, true);

curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$parameters = array(
 'user_auth' => array(
 'user_name' => 'admin',
 'password' => md5('admin'),
 ),
 );
$json = json_encode($parameters);
$postArgs = array(
 'method' => 'login',
 'input_type' => 'JSON',
 'response_type' => 'JSON',
 'rest_data' => $json
 );
 
echo json_encode($postArgs);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postArgs);

$response = curl_exec($curl);

$response = curl_exec($curl);
if (!$response) {
 die("Connection Failure.\n");
}

$result = json_decode($response);
if ( !is_object($result) ) {
 var_dump($response);
 die("Error handling result.\n");
}
if ( !isset($result->id) ) {
 die("Error: {$result->name} - {$result->description}\n.");
}
// Get the session id
$sessionId = $result->id;
echo $sessionId;

Please see this helps you

Thanks. Your comment made me thing “maybe I’m supposed to send the entire body as JSON, not x-www-form-urlencoded”. I tried that, but it seems to work less well as I get back the class / description of the service instead of an error or actual data.

Is it possible that you can send the raw request that’s being generated/sent by curl?

sure thing:

curl -L "https://yourSystemUrl/service/v4/rest.php" ^
-H "Content-Type: application/x-www-form-urlencoded" ^
-H "Cookie: PHPSESSID=thcl3p0eid0ldc64f7a9ma7mup" ^
-d "input_type=JSON" ^
-d "response_type=JSON" ^
-d "rest_data=%7B%22user_auth%22%3A%7B%22user_name%22%3A%22yourUser%22%2C%22password%22%3A%22yourUserPwAsMd5%22%2C%22version%22%3A%221%22%7D%2C%22application%22%3A%22test%22%7D" ^
-d "method=login"

should work, I’ve altered a working example from postman and exported it as curl example.

<?php

$url = 'http://localhost/suitecrm/service/v4_1/rest.php';

$curl = curl_init($url);

curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

// Prepare the parameters
$parameters = array(
    'user_auth' => array(
        'user_name' => 'admin',
        'password' => md5('admin'),
    ),
);
$json = json_encode($parameters);

// Prepare the post arguments
$postArgs = array(
    'method' => 'login',
    'input_type' => 'JSON',
    'response_type' => 'JSON',
    'rest_data' => $json
);

// Set the POST fields
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($postArgs));

// Set the Content-Type header
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));

$response = curl_exec($curl);

if ($response === false) {
    die("Connection Failure: " . curl_error($curl) . "\n");
}

$result = json_decode($response);
if (!is_object($result)) {
    var_dump($response);
    die("Error handling result.\n");
}
if (!isset($result->id)) {
    die("Error: {$result->name} - {$result->description}\n.");
}

// Get the session id
$sessionId = $result->id;
echo $sessionId;

// Close the cURL session
curl_close($curl);
?>

The following is working:

curl -g -X POST "http://localhost/suitecrm/service/v4_1/rest.php?method=login&input_type=JSON&response_type=JSON&rest_data={%22user_auth%22%3A{%22user_name%22%3A%22admin%22%2C%22password%22%3A%2221232f297a57a5a743894a0e4a801fc3%22}}"

Thanks for the curl commands. I tried them both, but I still get null values within the login function.

I also tried the PHP example and I get the same result (null inputs).

Note that I’m using SuiteCRM 8.7.0

I think with version 8, youi might need to include /legacy/… in the URL

Thanks, but I can see that my request is making it to the proper endpoint (PHP function). See this related thread for more info.

Edit: looks like you’re already there!