【问题标题】:CLIO API - Internal Server Error - Create CommunicationCLIO API - 内部服务器错误 - 创建通信
【发布时间】:2018-12-17 23:00:59
【问题描述】:

我正在尝试将我的旧 v2 应用程序更新到 v4。我目前遇到一个问题,当我尝试使用实现 RestSharp 的 C# 创建通信时收到“内部服务器错误”消息。我的架构如下:

public class CommunicationList
{
    public List<MakeCommunication> data { get; set; }
}

public class MakeCommunication
{
    public string body { get; set; }
    public DateTime date { get; set; }
    public NestedMatter matter { get; set; }
    public string subject { get; set; }
    public string type { get; set; }

}

public class NestedMatter
{
    public int id { get; set; }
}

我正在使用适当的数据填充对象。我对 RestSharp POST 的设置如下:

var request = new RestRequest("api/v4/communications.json", Method.POST);

        request.AddHeader("Authorization", "Bearer " + ConfigIt.readConfiguration("token"));
        request.AddParameter("fields", "body, date, matter{id}, subject, type");

我在不使用 AddJsonBody 方法的情况下序列化对象,因为我的研究让我相信 AddJsonBody 方法正在生成格式错误的 json,因此我使用以下代码来序列化对象:

request.RequestFormat = DataFormat.Json;

request.AddBody(commWrapper);

comWrapper 是下面的 CommunicationList 类型的对象。

得到一个通用的内部服务器错误并没有为我指明调试这个东西的任何方向。有人见过类似的问题吗?有什么建议吗?

感谢您提供的任何帮助,我的眼睛在这一点上交叉。

更新 - 12 月 15 日星期六


我对此做了更多的挖掘。使用 Fiddler 我能够验证这是发送到服务器的内容:

POST https://app.goclio.com/api/v4/communications.json HTTP/1.1
Authorization: Bearer ******************************
Accept: application/json, text/json, text/x-json, text/javascript, 
application/xml, text/xml
User-Agent: RestSharp/106.5.4.0
Content-Type: application/json
Host: app.goclio.com
Content-Length: 151
Accept-Encoding: gzip, deflate
Connection: Keep-Alive

{"data":[{"body":"test email for debug","date":"2018-12-15T14:23:23Z","matter:{"id":1035117666},"subject":"test","type":"EmailCommunication"}]}

我回到https://app.clio.com/api/v4/documentation#operation/Communication#create 的 api 文档,仔细检查我是否发送了正确的请求。我相信它看起来是正确的,但显然我遗漏了一些东西。

这是我从服务器返回的响应。

HTTP/1.1 500 Internal Server Error
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Status: 500 Internal Server Error
X-RateLimit-Limit: 600
X-RateLimit-Reset: 1544883900
X-RateLimit-Remaining: 599
X-Request-Id: 41199f9a-f569-4688-97a7-04b309cf85ed
X-Frame-Options: SAMEORIGIN
Cache-Control: private, no-cache, no-store, must-revalidate
X-XSS-Protection: 1; mode=block
X-API-VERSION: 4.0.5
X-Content-Type-Options: nosniff
Date: Sat, 15 Dec 2018 14:24:09 GMT
Server: nginx
Content-Length: 75

{"error":{"type":"InternalServiceError","message":"Something went wrong."}}

我希望有人可能以前遇到过这种情况。非常感谢任何帮助。

【问题讨论】:

    标签: clio-api


    【解决方案1】:

    看起来您在请求负载中为data 发送的值是一个数组,而不是一个对象。您链接的文档页面的侧栏中有一个正确数据格式的示例。

    您提供的有效负载中似乎也包含无效的 json。 matter 后面少了一个双引号。

    因此,如果您将有效负载更改为如下所示,它应该可以工作(为提高可读性而扩展):

    {
        "data":{
            "body":"test email for debug",
            "date":"2018-12-15T14:23:23Z",
            "matter":{"id":1035117666},
            "subject":"test",
            "type":"EmailCommunication"
        }
    }
    

    【讨论】:

    • 我正在发送一组 json 对象,该示例恰好有一个成员。这是从 api 的 v2 的变化吗?我应该改用批量操作吗?目标是能够在 Outlook 中选择多封电子邮件并一次将它们链接到一个问题(我还在另一个步骤中创建一个时间条目)。不幸的是,我必须弄清楚格式错误的 json 问题,因为我使用的是 RestSharp 接口,所以它必须在该代码中遇到错误。
    • 我不熟悉 v2 的 api,但是,在 v4 中,您会使用批量操作以这种方式创建多个对象。
    猜你喜欢
    • 1970-01-01
    • 2015-07-27
    • 1970-01-01
    • 2013-06-11
    • 2011-08-24
    • 2014-11-04
    • 1970-01-01
    • 2021-05-09
    • 1970-01-01
    相关资源
    最近更新 更多