Results 1 to 2 of 2

Thread: Problem trying to interface with sugar through REST

  1. #1
    wmanns is offline Junior Member
    Join Date
    Jun 2010
    Posts
    1

    Default Problem trying to interface with sugar through REST

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

  2. #2
    agcopley is offline Sugar Community Member
    Join Date
    Nov 2007
    Location
    Santiago, Chile
    Posts
    204

    Default Re: Problem trying to interface with sugar through REST


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Sugar 6 and the new interface
    By decrook@gmail.com in forum Help
    Replies: 1
    Last Post: 2010-06-15, 05:37 PM
  2. Replies: 0
    Last Post: 2009-08-20, 03:56 PM
  3. Replies: 5
    Last Post: 2007-06-06, 06:13 AM
  4. Replies: 5
    Last Post: 2005-02-01, 02:18 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •