duplicate entry created from rest call


$url = "https://yoursuiteinstall.com/service/v4_1/rest.php";

function restRequest($method, $arguments){
	global $url;

	$curl = curl_init($url);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	$post = array(
		"method" => $method,
		"input_type" => "JSON",
		"response_type" => "JSON",
		"rest_data" => json_encode($arguments),

	curl_setopt($curl, CURLOPT_POSTFIELDS, $post);

	$result = curl_exec($curl);
	return json_decode($result,1);

function createlead($firstname,$lastname,$email,$phone,$howtheyheard)
$userAuth = array(
	'user_name' => 'username',
	'password' => md5('password'),
$appName = 'My SuiteCRM REST Client';
$nameValueList = array();
$args = array(
	'user_auth' => $userAuth,
	'application_name' => $appName,
	'name_value_list' => $nameValueList

$result = restRequest('login',$args);
echo "<pre>";
$sessId = $result['id'];

$entryArgs = array(
	'session' => $sessId, 					// Session id - retrieved from login call
	'module_name' => 'Leads', 		// Module to get_entry_list for
	'name_value_list ' => array(    
    'assigned_user_id'                          => '592bb305-8073-9ddd-2214-58c1c81f0245',
    'status'                                    => 'New',
    'first_name'                                => $firstname,
    'last_name'                                 => $lastname,
    'email1'                                    => $email,
    'phone_home'                                => $phone,
    'web_how_they_heard_c'			=> $howtheyheard,
$result = restRequest('set_entry',$entryArgs);
echo "<pre>";
createlead("Bill","Lee","billlee@test2.com","55555555555","Online rest call");

Can any of you advise me why this created 2 entries with the same information when i run this rest call. Anyone can test this just change your parameters. $url, $username, $password and it should work for you.

I have checked your code,it’s working fine, creating only lead per request.

You may some issue with your logic hooks or workflow , which is creating duplicate lead.

Try these steps.

  1. Rename logic_hooks.php from custom/modules/Leads to logic_hooks_old.php

  2. Create a directory named “Disabled” under custom/Extension/modules/Leads/Ext/LogicHook , move all files from this folder to recently created "Disabled’ folder.

go for repair and then put a Api request again, Hope that solves your issue, then you will need further dig out exact issue.

At this point i can only say above code looks fine.

1 Like