1

我想通过 API 将带有附件的工单添加到 Freshdesk。我知道如何添加没有附件的票,并且工作正常。但是,我不知道如何添加带有附件的票。我想用 JSON 做到这一点。我试过这样的事情:

string json = $"{{\"helpdesk_ticket\": {{\"subject\":\"{subject}\",\"description_html\":\"{fullDescription}\",\"name\":\"{user}\",\"attachments\":{{\"\":[{{\"resource\":\"{bytes}\"}}]}}}}}}";

在字节字段中,我有我的文件字节数组。但它不起作用。有人可以帮我将 JSON 格式的文件传递给 Freshdesk API 吗?

4

2 回答 2

3

我也为此苦苦挣扎。

你试过了吗: https ://github.com/freshdesk/fresh-samples/blob/v1/jquery_samples/create_with_attachment.html

于 2017-02-08T09:30:41.067 回答
0

我用 RestSharp 解决了这个问题。这是 REST API 的简单工具。当我发送带有附件的票时,我使用以下代码:

        var client = new RestClient(_freshdeskUrl);
        client.Authenticator = new HttpBasicAuthenticator(_apiKey, "X");
        var request = new RestRequest("", Method.POST);

        request.AddHeader("Accept", "application/json");
        request.AddHeader("Content-Type", "multipart/form-data");
        request.AddParameter("email", "example@example.com");
        request.AddParameter("subject", "Subject");
        request.AddParameter("description", "Description");
        request.AddParameter("name", "Name");
        request.AddParameter("status", "2");
        request.AddParameter("priority", "1");
        request.AddFile("attachments[]", bytes, "Logs.txt", "text/plain");

        var response = client.Execute(request);

当我发送不带附件的票时,我使用以下代码:

        RestClient client = new RestClient(_freshdeskUrl);
        client.Authenticator = new HttpBasicAuthenticator(_apiKey, "X");
        RestRequest request = new RestRequest("", Method.POST);

        request.AddHeader("Accept", "application/json");

        request.AddJsonBody(new
        {
            email = "example@example.com",
            subject = "Subject",
            description = "Description",
            name = "Name",
            status = 2,
            priority = 1
        });

        var response = client.Execute(request);
于 2017-02-28T09:51:14.797 回答