rest - SugarCRM REST API 错误

标签 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;

更改了用户名、密码和 url 以匹配我的设置,但我收到一条错误消息

No direct script access allowed

我试图在网上搜索这个但找不到任何相关的解决方案。 我使用的是sugarCRM 6.5.0RC2版本

问候, 阿南德·乔希

最佳答案

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

要验证它,请尝试从浏览器转到您的 API URL: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 包装器。我用这个:https://github.com/asakusuma/SugarCRM-REST-API-Wrapper-Class

关于rest - SugarCRM REST API 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11359097/

相关文章:

node.js - 如何保护开放的 REST API 免受 Node.js 中的滥用?

javascript - SugarCRM - 如何将 onClick 事件添加到现有 HTML/Checkbox

php - SugarCRM 请求超时

mysql - 如何导出 sugarcrm 中的潜在客户历史记录部分?

java - suguacrm 6.4.4 中的重复铅

java - 以 sinch 形式收集输入

django - Django 中序列化器 to_internal_value 方法的用途是什么

api - 内容范围 header - 允许的单位?

javascript - 如何测试对 REST 服务的调用

ssl - SugarCRM 6.2 CE Imap 模块自签名证书错误