【问题标题】:Freshdesk API add ticket with attachmentFreshdesk API 添加带有附件的工单
【发布时间】:2017-02-06 18:16:24
【问题描述】:

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

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

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

【问题讨论】:

标签: c# .net json api freshdesk


【解决方案1】:

【讨论】:

    【解决方案2】:

    我用 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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多