I have just installed sugar to try it out and am having a problem getting the REST interface to work properly. Here is the code I am using to login (which is from the sugar website):
Code:$url = 'http://192.168.25.28/service/v2/rest.php'; $user_name = 'admin'; $user_password = 'resources'; //$url = $sugar_config[‘site_url’] . “/service/v2/rest.php”; function doRESTCALL($url, $method, $data) { ob_start(); $ch = curl_init(); $headers = (function_exists('getallheaders')) ? getallheaders() : array(); $_headers = array(); foreach($headers as $k=>$v){ $_headers[strtolower($k)] = $v; } // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $_headers); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0 ); $post_data = 'method=' . $method . '&input_type=json&response_type=json'; //$json = getJSONobj(); //$jsonEncodedData = $json->encode($data, false); $jsonEncodedData = json_encode($data); $post_data = $post_data . "&rest_data=" . $jsonEncodedData; curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); $result = curl_exec($ch); curl_close($ch); $result = explode("\r\n\r\n", $result, 2); print_r($result[1]); //$response_data = $json->decode($result[1]); $response_data = json_decode($result[1]); ob_end_flush(); //print_r($response_data); return $response_data; } $result = doRESTCALL($url, 'login',array('user_auth' => array('user_name' => $user_name, 'password' => md5($user_password), 'version'=>'.01'), 'application_name'=>'SoapTest'));


LinkBack URL
About LinkBacks



Reply With Quote

Bookmarks