SugarCRM Rest api 函数响应总是被最后 2 个字符修剪
SugarCRM Rest api function response always trimmed by last 2 characters
我在 SugarCRM REST 函数中遇到了问题。我已经创建了我正在使用的 Sugar 模块。我有用于 REST 调用的 dashlet 文件,其中有函数,因此无论我从那个函数 return,该响应总是截断最后 2 个字符。
最初我认为这是来自 REST API 的问题,但现在我对响应进行了硬编码,但问题仍然存在。
假设我 return "Hello World",然后我得到响应 "Hello Wor"
<?php
require_once('include/api/SugarApi.php');
require_once 'include/SugarTheme/SidecarTheme.php';
require_once('custom/clients/base/helper/SecurityHelper.php');
class FreshDashletApi extends SugarApi
{
public function registerApiRest()
{
return array(
'freshdeskdashlet' => array(
'reqType' => 'GET',
'path' => array('freshdeskdashlet'),
'pathVars' => array(''),
'method' => 'getFreshdeskDashlet',
'shortHelp' => '',
'longHelp' => '',
),
'ticketfields' => array(
'reqType' => 'GET',
'path' => array('ticketfields'),
'pathVars' => array(''),
'method' => 'getCustomFields',
'shortHelp' => '',
'longHelp' => '',
),
);
}
public function getFreshdeskDashlet($api, $args)
{
$data = array (
'ticket_json' =>
array (
0 =>
array (
'associates_rdb' => NULL,
'association_type' => NULL,
'cc_email' =>
array (
'cc_emails' =>
array (
),
'fwd_emails' =>
array (
),
'reply_cc' =>
array (
),
'tkt_cc' =>
array (
),
),
'created_at' => '2019-02-05T15:06:30+05:30',
'deleted' => false,
'delta' => true,
'description' => 'This is our test ticket for Sugar CRM Test',
'description_html' => '
This is our test ticket for Sugar CRM Test
',
'dirty' => 0,
'display_id' => 22,
'due_by' => '2019-02-08T15:06:30+05:30',
'email_config_id' => NULL,
'frDueBy' => '2019-02-06T15:06:30+05:30',
'fr_escalated' => false,
'group_id' => NULL,
'id' => 42017573142,
'internal_agent_id' => NULL,
'internal_group_id' => NULL,
'isescalated' => false,
'owner_id' => NULL,
'parent_ticket_id' => NULL,
'priority' => 1,
'requester_id' => 42008575970,
'responder_id' => NULL,
'sl_escalation_level' => NULL,
'sl_manual_dueby' => NULL,
'sl_merge_parent_ticket' => NULL,
'sl_product_id' => NULL,
'sl_skill_id' => NULL,
'sl_sla_policy_id' => NULL,
'sla_state' => 0,
'source' => 3,
'spam' => false,
'st_survey_rating' => NULL,
'status' => 2,
'subject' => 'Sugar Test',
'ticket_type' => 'Question',
'to_email' => NULL,
'trained' => false,
'updated_at' => '2019-02-05T15:06:30+05:30',
'urgent' => false,
'status_name' => 'Open',
'requester_status_name' => 'Being Processed',
'priority_name' => 'Low',
'source_name' => 'Phone',
'requester_name' => 'Amol Rokade',
'responder_name' => 'No Agent',
'to_emails' => NULL,
'product_id' => NULL,
'custom_field' =>
array (
),
),
),
'domain' => 'abc.pqr.com',
'credentials' => 'X2Y9CfvfdvseUUZvdfvfdvvfvf7e3Pud1tI',
'ssl' => 'http',
'ticket_fields' =>
array (
'ticket_fields' =>
array (
'ticket_type' =>
array (
'Question' => 'Question',
'Incident' => 'Incident',
'Problem' => 'Problem',
'Feature Request' => 'Feature Request',
),
'ticket_status' =>
array (
'Open' => 2,
'Pending' => 3,
'Resolved' => 4,
'Closed' => 5,
'Waiting on Customer' => 6,
'Waiting on Third Party' => 7,
),
'ticket_priority' =>
array (
'Low' => 1,
'Medium' => 2,
'High' => 3,
'Urgent' => 4,
),
'ticket_group' =>
array (
'Product Management' => 42000076370,
'QA' => 42000076371,
'Sales' => 42000076372,
),
'agent' =>
array (
'John Deo' => 42001642325,
),
),
),
'email' => 'John@gmail.co.in',
'tickets' =>
array (
0 =>
array (
'ticket_field' =>
array (
'active' => true,
'column_name' => NULL,
'created_at' => '2018-05-02T10:07:06+05:30',
'default' => true,
'description' => 'Ticket status',
'editable_in_portal' => false,
'field_options' => NULL,
'field_type' => 'default_status',
'flexifield_coltype' => NULL,
'flexifield_def_entry_id' => NULL,
'id' => 42000265137,
'import_id' => NULL,
'label' => 'Status',
'label_in_portal' => 'Status',
'level' => NULL,
'name' => 'status',
'parent_id' => NULL,
'position' => 4,
'prefered_ff_col' => NULL,
'required' => true,
'required_for_closure' => false,
'required_in_portal' => false,
'ticket_form_id' => 42000023745,
'updated_at' => '2018-05-02T10:07:06+05:30',
'visible_in_portal' => true,
'choices' =>
array (
0 => 'Open',
1 => 'Pending',
2 => 'Resolved',
3 => 'Closed',
4 => 'Waiting on Customer',
5 => 'Waiting on Third Party',
),
'nested_ticket_fields' =>
array (
),
),
),
),
'module' => 'Contact',
);
return $data;
}
}
在控制台中,出现以下错误。
HttpError {request: HttpRequest, status: 200, responseText: "↵↵{"ticket_json":[{"associates_rdb":null,"associat…"],"nested_ticket_fields":[]}}],"module":"Contact", textStatus: "parsererror", errorThrown:
但不幸的是,我无法找到它确切执行 JSON 解析的位置以及为什么只有最后 2 个字符被截断。
非常感谢任何帮助。
I have fixed the issue at my own.
The issue was the PHP file encoded wrong.
The old files were saved as UTF8 with BOM, but I changed to UTF-8 and its working fine now.
BOM consists of some extra chars before the content of the file and also used ob_clean before sending the response.
我在 SugarCRM REST 函数中遇到了问题。我已经创建了我正在使用的 Sugar 模块。我有用于 REST 调用的 dashlet 文件,其中有函数,因此无论我从那个函数 return,该响应总是截断最后 2 个字符。
最初我认为这是来自 REST API 的问题,但现在我对响应进行了硬编码,但问题仍然存在。
假设我 return "Hello World",然后我得到响应 "Hello Wor"
<?php
require_once('include/api/SugarApi.php');
require_once 'include/SugarTheme/SidecarTheme.php';
require_once('custom/clients/base/helper/SecurityHelper.php');
class FreshDashletApi extends SugarApi
{
public function registerApiRest()
{
return array(
'freshdeskdashlet' => array(
'reqType' => 'GET',
'path' => array('freshdeskdashlet'),
'pathVars' => array(''),
'method' => 'getFreshdeskDashlet',
'shortHelp' => '',
'longHelp' => '',
),
'ticketfields' => array(
'reqType' => 'GET',
'path' => array('ticketfields'),
'pathVars' => array(''),
'method' => 'getCustomFields',
'shortHelp' => '',
'longHelp' => '',
),
);
}
public function getFreshdeskDashlet($api, $args)
{
$data = array (
'ticket_json' =>
array (
0 =>
array (
'associates_rdb' => NULL,
'association_type' => NULL,
'cc_email' =>
array (
'cc_emails' =>
array (
),
'fwd_emails' =>
array (
),
'reply_cc' =>
array (
),
'tkt_cc' =>
array (
),
),
'created_at' => '2019-02-05T15:06:30+05:30',
'deleted' => false,
'delta' => true,
'description' => 'This is our test ticket for Sugar CRM Test',
'description_html' => '
This is our test ticket for Sugar CRM Test
',
'dirty' => 0,
'display_id' => 22,
'due_by' => '2019-02-08T15:06:30+05:30',
'email_config_id' => NULL,
'frDueBy' => '2019-02-06T15:06:30+05:30',
'fr_escalated' => false,
'group_id' => NULL,
'id' => 42017573142,
'internal_agent_id' => NULL,
'internal_group_id' => NULL,
'isescalated' => false,
'owner_id' => NULL,
'parent_ticket_id' => NULL,
'priority' => 1,
'requester_id' => 42008575970,
'responder_id' => NULL,
'sl_escalation_level' => NULL,
'sl_manual_dueby' => NULL,
'sl_merge_parent_ticket' => NULL,
'sl_product_id' => NULL,
'sl_skill_id' => NULL,
'sl_sla_policy_id' => NULL,
'sla_state' => 0,
'source' => 3,
'spam' => false,
'st_survey_rating' => NULL,
'status' => 2,
'subject' => 'Sugar Test',
'ticket_type' => 'Question',
'to_email' => NULL,
'trained' => false,
'updated_at' => '2019-02-05T15:06:30+05:30',
'urgent' => false,
'status_name' => 'Open',
'requester_status_name' => 'Being Processed',
'priority_name' => 'Low',
'source_name' => 'Phone',
'requester_name' => 'Amol Rokade',
'responder_name' => 'No Agent',
'to_emails' => NULL,
'product_id' => NULL,
'custom_field' =>
array (
),
),
),
'domain' => 'abc.pqr.com',
'credentials' => 'X2Y9CfvfdvseUUZvdfvfdvvfvf7e3Pud1tI',
'ssl' => 'http',
'ticket_fields' =>
array (
'ticket_fields' =>
array (
'ticket_type' =>
array (
'Question' => 'Question',
'Incident' => 'Incident',
'Problem' => 'Problem',
'Feature Request' => 'Feature Request',
),
'ticket_status' =>
array (
'Open' => 2,
'Pending' => 3,
'Resolved' => 4,
'Closed' => 5,
'Waiting on Customer' => 6,
'Waiting on Third Party' => 7,
),
'ticket_priority' =>
array (
'Low' => 1,
'Medium' => 2,
'High' => 3,
'Urgent' => 4,
),
'ticket_group' =>
array (
'Product Management' => 42000076370,
'QA' => 42000076371,
'Sales' => 42000076372,
),
'agent' =>
array (
'John Deo' => 42001642325,
),
),
),
'email' => 'John@gmail.co.in',
'tickets' =>
array (
0 =>
array (
'ticket_field' =>
array (
'active' => true,
'column_name' => NULL,
'created_at' => '2018-05-02T10:07:06+05:30',
'default' => true,
'description' => 'Ticket status',
'editable_in_portal' => false,
'field_options' => NULL,
'field_type' => 'default_status',
'flexifield_coltype' => NULL,
'flexifield_def_entry_id' => NULL,
'id' => 42000265137,
'import_id' => NULL,
'label' => 'Status',
'label_in_portal' => 'Status',
'level' => NULL,
'name' => 'status',
'parent_id' => NULL,
'position' => 4,
'prefered_ff_col' => NULL,
'required' => true,
'required_for_closure' => false,
'required_in_portal' => false,
'ticket_form_id' => 42000023745,
'updated_at' => '2018-05-02T10:07:06+05:30',
'visible_in_portal' => true,
'choices' =>
array (
0 => 'Open',
1 => 'Pending',
2 => 'Resolved',
3 => 'Closed',
4 => 'Waiting on Customer',
5 => 'Waiting on Third Party',
),
'nested_ticket_fields' =>
array (
),
),
),
),
'module' => 'Contact',
);
return $data;
}
}
在控制台中,出现以下错误。
HttpError {request: HttpRequest, status: 200, responseText: "↵↵{"ticket_json":[{"associates_rdb":null,"associat…"],"nested_ticket_fields":[]}}],"module":"Contact", textStatus: "parsererror", errorThrown:
但不幸的是,我无法找到它确切执行 JSON 解析的位置以及为什么只有最后 2 个字符被截断。
非常感谢任何帮助。
I have fixed the issue at my own.
The issue was the PHP file encoded wrong.
The old files were saved as UTF8 with BOM, but I changed to UTF-8 and its working fine now.
BOM consists of some extra chars before the content of the file and also used ob_clean before sending the response.