SugarCRM REST api错误

时间:2012-07-06 09:01:18

标签: rest sugarcrm

我正在尝试通过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版本

此致 阿南德乔希

2 个答案:

答案 0 :(得分:0)

这条线不应该是......

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

答案 1 :(得分:0)

您可能在WEB服务器上配置了一些防御功能,允许您只访问index.php。

要验证它,请尝试从浏览器转到API网址:http://YOUR_DOMAIN_NAME/service/v4_1/rest.php

或/并从终端:wget http://YOUR_DOMAIN_NAME/service/v4_1/rest.php

运行

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

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

另外,我建议您使用一些开源SugarCRM REST API包装器。我用这个:https://github.com/asakusuma/SugarCRM-REST-API-Wrapper-Class

相关问题