CLIO API - Internal Server Error - Create Communication

292 Views Asked by At

I am attempting to update my old v2 application to v4. I am currently running into a problem where I am getting an "Internal Server Error" message when I try to create a communication using C# implementing RestSharp. My schema is as follows:

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; }
}

I am populating the objects with the appropriate data. My setup for the RestSharp POST is as follows:

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");

I am serializing the object without the AddJsonBody method because my research led me to believe that AddJsonBody method was producing malformed json so I am using the following code to serialize the objects:

request.RequestFormat = DataFormat.Json;

request.AddBody(commWrapper);

comWrapper is an object of type CommunicationList from below.

Getting a generic Internal Server Error really isn't pointing me in any direction for debugging this thing. Anyone seen a similar issue? Any suggestions?

Thanks for any help you can give, my eyes are going crossed at this point.

UPDATE - Saturday Dec 15th


I have done some more digging on this. Using Fiddler I was able to verify that this is what is being sent to the server:

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"}]}

I went back to the api documentation at https://app.clio.com/api/v4/documentation#operation/Communication#create to double check that I was sending the right request. I believe it looks correct but clearly I am missing something.

This is the response I am getting back from the server.

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."}}

I am hoping that someone may have encountered this before. Any help is greatly appreciated.

1

There are 1 best solutions below

2
On BEST ANSWER

It looks like the value you're sending for data in your request payload is an Array, not an Object. There is an example of the correct data format in the sidebar on the documentation page that you linked.

It also looks like the payload you provided has invalid json in it. There is a double-quote missing after matter.

So if you change your payload to look something like this, it should work (expanded for readability):

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