gpt4 book ai didi

rest - SugarCRM REST API 错误

转载 作者:行者123 更新时间:2023-12-02 05:06:09 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com