SugarCRM查询自定义端点中的参数

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

Background

我正在SugarCRM中构建一个自定义REST端点,它将两个模块连接在一起并返回结果。我需要允许用户以查询参数的形式传递可选数据。目前端点如下所示:

http://base-url.com/api/customer/{customer_id}/branch/{branch_id}/offset/{offset}

但是这需要我传入一个offset值。相反,我希望端点看起来像

http://base-url.com/api/customer/{customer_id}/branch/{branch_id}?offset={offset}

我已经检查了SugarCRM开发人员文档并在线检查但是找不到任何利用查询参数的确定示例。

My Code

以下是我的代码。此代码示例与上面列出的第一个端点匹配。我的目标是将offset参数修改为查询字符串而不是路径变量

<?php

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

class LinkLeadsApi extends SugarApi
{
    public function registerApiRest()
    {
        return array(
            'LinkLeadsEndpoint' => array(
                'reqType' => 'GET',
                'noLoginRequired' => false,
                'path' => array('customer', '?', 'branch', '?', 'offset', '?'),
                'pathVars' => array('customer', 'customer_id', 'branch', 'branch_id', 'offset', 'offset_num'),
                'method' => 'GetLinkLeads',
                'shortHelp' => 'Retrieve Leads for Latham Link',
                'longHelp' => 'Retrieve Leads for Latham Link'
            )
        );
    }

    public function GetLinkLeads($api, $args)
    {
         $seed = BeanFactory::newBean('w002_ConsumerLeads');

         $q = new SugarQuery();
         $q->from($seed);
        $q->limit($args['offset_num']);

        return $q->execute();

    }
}

?>
php rest api sugarcrm
1个回答
1
投票

您的查询字符串仍可通过$ _REQUEST变量在同一PHP界面中访问,但它们也可在$ args中使用:

public function GetLinkLeads($api, $args)
{
    $GLOBALS['log']->fatal("args: " . print_r($args, true));
    $GLOBALS['log']->fatal("request: " . print_r($_REQUEST, true));

}

url:{sugar} / rest / v10 / customer / 1 / branch / 2 / offset / 3?qs = 4

sugarcrm.log

Wed Apr 24 12:06:27 2019 [19200][-none-][FATAL] args: Array
(
    [__sugar_url] => v10/customer/1/branch/2/offset/3
    [qs] => 4
    [customer] => customer
    [customer_id] => 1
    [branch] => branch
    [branch_id] => 2
    [offset] => offset
    [offset_num] => 3
)

Wed Apr 24 12:06:27 2019 [19200][-none-][FATAL] request: Array
(
    [__sugar_url] => v10/customer/1/branch/2/offset/3
    [qs] => 4
)
© www.soinside.com 2019 - 2024. All rights reserved.