首页 > 解决方案 > SuiteCrm Rest API:调用 POST 或 PUT 时 JSON 正文属性引发错误

问题描述

我正在使用邮递员来调用 SuiteCRM REST API。

我试图调用这个端点

PATCH http://{{suitecrm-url}}/Api/V8/module

我已将此有效负载添加到正文(内容类型:应用程序/Json):

{
  "data": {
    "type": "Accounts",
    "id": "3a3ae651-d509-2508-7dc4-5be2e51cc96b",
    "attributes": {
        "name": "name with space"
    }
  }
}

执行请求时,SuiteCRM 会给出以下响应:

{
  "errors": {
    "status": 400,
    "title": null,
    "detail": "The option \"attributes\" with value array is invalid."
  }
}

我发现问题出在值中的空格:当我尝试使用值“namewithspace”时,它起作用了。

任何人都知道如何解决这个问题?

提前致谢

标签: restsuitecrm

解决方案


我在 github 上发现了这个问题,解决了我的问题:

https://github.com/salesagility/SuiteCRM/issues/6452

简而言之,为了让它工作,我不得不修改文件

/Api/V8/Params/Options/Fields.php

并替换此行

const REGEX_FIELD_PATTERN = '/[^\w-,]/';

const REGEX_FIELD_PATTERN = '/[^\w-,\s\]/';

github中提到的人:

这仅用于临时修复而不是安全升级


推荐阅读