AnsweredAssumed Answered

how to add dropdown values via rest web services

Question asked by Kinjal Parikh on Jun 15, 2016
Latest reply on Jun 18, 2016 by Ramana Raju Santhana

Hi,

I want to add the dropdown values(for lead_source field) and also the date_closed field in the set_entry method of rest web services. I have tried a lot of ways but i am not able to get a coorect solution. Can anyone please help me on the same.

Kindly find my code below

 

<?php

 

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

$username = "admin";

$password = "password";

 

 

 

if(!isset($_POST)&&!isset($_POST)&&!isset($_POST)&&(!isset($_POST)||(!isset($_POST))))

{

$data = array();

 

$response = array("call_status" => '0', "err_msg" => 'Parameters Missing', "msg" => 'UnSuccessful', "data" => $data);

echo json_encode($response);

exit();

}

//function to make cURL request

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);

echo "</pre>";

*/

 

//get session id

$session_id = $login_result->id;

 

//create account


$set_entry_parameters = array(

//session id

"session" => $session_id,

 

//The name of the module from which to retrieve records.

"module_name" => "Leads",

 

//Record attributes

"name_value_list" => array(

"name_value_list" => array(

             array('name' => 'id', 'value' => $_REQUEST['id']),

  array('name' => 'number', 'value' => $_REQUEST['number']),

        array('name' => 'first_name', 'value' => $_REQUEST['first_name']),

        array('name' => 'last_name', 'value' => $_REQUEST['last_name']),

        array('name' => 'title', 'value' => $_REQUEST['title']),

        array('name' => 'department', 'value' => $_REQUEST['department']),

        array('name' => 'phone_mobile', 'value' => $_REQUEST['phone_mobile']),

  array('name' => 'phone_work', 'value' => $_REQUEST['phone_work']),

array('name' => 'lead_source', 'value' => $_REQUEST['lead_source']),

array('name' => 'date_closed', 'value' => $_REQUEST['date_closed']),

),

);

 

$set_entry_result = call("set_entry", $set_entry_parameters, $url);

 

/* echo "<pre>";

print_r($set_entry_result);

echo "</pre>";*/

$array = json_decode(json_encode($set_entry_result), True);

$user_id= $array;

$data = array();

$element1 = array ("id" => $user_id);

array_push($data, $element1);

$response = array("call_status" => '1', "err_msg" => '', "msg" => 'Successful', "data" => $data);

echo json_encode($response);

exit();

 

//echo json_encode($set_entry_result);

 

?>

Outcomes