2012-07-06 121 views
3

我试图通过Sugarcrm REST api检索自定义模块数据,但我无法做到,因为我甚至无法使用文档代码登录,我尝试了与文档SugarCRM REST api错误

中给出的相同的操作
<?php 

// specify the REST web service to interact with 
$url = 'localhost/~jmertic/sugarcrm/service/v4_1/rest.php'; 

// Open a curl session for making the call 
$curl = curl_init($url); 

// Tell curl to use HTTP POST 
curl_setopt($curl, CURLOPT_POST, true); 

// Tell curl not to return headers, but do return the response 
curl_setopt($curl, CURLOPT_HEADER, false); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 

// Set the POST arguments to pass to the Sugar server 
$parameters = array(
    'user_auth' => array(
     'user_name' => 'username', 
     'password' => md5('password'), 
     ), 
    ); 
$json = json_encode($parameters); 
$postArgs = array(
    'method' => 'login', 
    'input_type' => 'JSON', 
    'response_type' => 'JSON', 
    'rest_data' => $json, 
    ); 
curl_setopt($curl, CURLOPT_POSTFIELDS, $postArgs); 

// Make the REST call, returning the result 
$response = curl_exec($curl); 

// Convert the result from JSON format to a PHP array 
$result = json_decode($response); 
if (!is_object($result)) { 
    die("Error handling result.\n"); 
} 
if (!isset($result->id)) { 
    die("Error: {$result->name} - {$result->description}\n."); 
} 

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

改变用户名,密码和网址,以配合我的设置,但我得到一个错误,说明

No direct script access allowed 

我试图寻找这个网站上,但无法找到任何相关的解决方案。 我使用SugarCRM的6.5.0RC2版本

问候, 阿南德·乔希

+0

是否有任何其他的替代方案,如果这种方法不起作用? – 2012-07-06 09:43:17

回答

0

你可能已经在Web服务器上配置一些防御这只允许你访问index.php。

为了验证它,尝试从浏览器访问您的API网址:http://YOUR_DOMAIN_NAME/service/v4_1/rest.php

和/或从终端上运行:wget http://YOUR_DOMAIN_NAME/service/v4_1/rest.php

如果它显示了相同的消息,请检查您.httaccess此文件夹或/和您的Web服务器配置文件。

如果不是,您如何运行API测试脚本?通过CLI或浏览器?

另外我建议你使用一些开源的SugarCRM REST API Wrapper。我使用这一个:https://github.com/asakusuma/SugarCRM-REST-API-Wrapper-Class

0

不宜行是这样......

$url = 'http://yoursugarinstance/service/v4_1/rest.php'; 
+0

雅,我已经提到了相同的'代码'“改变了用户名,密码和url以匹配我的设置,但我得到一个错误,指出”代码“ – 2012-07-06 17:22:46