在 Suite CRM 中创建自定义 API V8

问题描述 投票:0回答:3

美好的一天!

我计划为帐户模块创建一个自定义 API,以便使用 API 获取和更新数据。我在我的帐户模块上创建了一个自定义字段(integration_ref_id),如果帐户存在或不存在,它将用作我的标识符。 检查以下有效负载请求示例

{
"consent_timestamp": "2021-04-13 09:45:00",
"integration_ref_id": "CUSREF-202104-ABCDEF0000003",
"last_name": "De la Cruz",
"first_name": "Juan",
"birthdate": "1995-03-25",
"mobile_number": "+639171234199",
"email": "[email protected]",
"location_code": "LOC0001",
"street_name": "Rose St.",
"landmarks": "Mcdo",
"gender": "male"
}

现在我在自定义文件夹上创建了自定义路由(custom/application/Ext/Api/V8/Config

<?php
$app->get('/my-route/{myParam}', 'MyCustomController:myCustomAction');

$app->get('/hello', function() {
    return 'Hello World!';
});

$app->get('/getCustomers', 'Api\V8\Controllers\CustomersController:getCustomers');

我将控制器放置在与路线相同的路径上。 (自定义/应用程序/Ext/Api/V8/控制器

这是我的控制器代码

<?php
namespace Api\V8\Controller;

if (!defined('sugarEntry') || !sugarEntry) {
    die('Not A Valid Entry Point');
}



class CustomersController extends BaseController
{
    public function getCustomers(Request $request, Response $response, array $args, GetRelationshipParams $params)
    {
        try {
            $jsonResponse = $this->relationshipService->getCustomers($request);
            return $this->generateResponse($response, $jsonResponse, 200);
        } catch (\Exception $exception) {
            return $this->generateErrorResponse($response, $exception, 400);
        }
    }
}

但是我在邮递员中遇到了这个错误 enter image description here

我一直在寻找,但我觉得有点困惑。顺便说一句,我是这个 SuiteCRM 的新手

问候!

suitecrm
3个回答
0
投票

没关系,我能弄清楚。我刚刚将下面的代码添加到我的控制器CustomeController.php

namespace Api\V8\Controller;
use Slim\Http\Response;
use Slim\Http\Request;

并将此添加到我的自定义controller.php

require 'custom/application/Ext/Api/V8/Controller/CustomersController.php';
use Api\V8\Controller;
use Slim\Container;

然后一切都应该正常工作。


0
投票

我目前安装了最新版本8.4。我创建了一个自定义模块,并且可以使用 API get 方法成功从模块中提取信息。据我了解,要在模块中发布新记录,我需要自定义 API,如此处所述。但是,引用的文件扩展 Slim 配置 custom/application/Ext/Api/V8/slim.php 或我假设的 public/legacy/custom/application/Ext/Api/V8/slim.php 不存在。

你的帖子让我相信我要在 /public/legacy**/cu**stom/application/Ext/Api/V8/Config/ 中创建一个文件;但是,我不清楚文件名应该是什么以及这是否确实是正确的位置。

此外,custom/application/Ext/Api/V8/Controller 位置实际上是 public/legacy/Api/V8/Controller 吗?或者是另一个需要在某处引用或扩展某些内容的位置文件名?


0
投票

错误“customController 不存在”是因为它没有加载到 suitecrm 的类映射文件中。 你可以检查这个文件vendor/composer/autoload_classmap.php

问题原因如果您查看根文件夹中的composer.json文件

"composer.json" 
"classmap": [
      "Api/"
    ]

这是做什么的,它会自动加载suitecrm Api文件夹中的所有类

解决方案:在此处添加一行custom/application/Ext/Api

"classmap": [
      "Api/",
      "custom/application/Ext/Api/"
    ]

保存后,在 suitecrm 的根文件夹中运行命令 composer dump-autoload 和这个 您可以通过查看自动加载的类数量的差异来交叉检查

© www.soinside.com 2019 - 2024. All rights reserved.