简体   繁体   English

Freshdesk API添加带附件的票证

[英]Freshdesk API add ticket with attachment

I want to add a ticket with an attachment to Freshdesk via the API. 我想通过API添加一张附有Freshdesk附件的票证。 I know how to add a ticket without an attachment, and it's working fine. 我知道如何在没有附件的情况下添加票证,而且工作正常。 However, I don't know how to add a ticket with an attachment. 但是,我不知道如何添加带附件的票证。 I want to do this with JSON. 我想用JSON做到这一点。 I tried something like this: 我试过这样的事情:

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

In the bytes field I have my file bytes array. 在bytes字段中,我有我的文件字节数组。 But it's not working. 但它不起作用。 Can someone help me to pass a file in JSON to the Freshdesk API? 有人可以帮我把JSON中的文件传递给Freshdesk API吗?

I resolved this problem with RestSharp. 我用RestSharp解决了这个问题。 This is simple tool to REST API. 这是REST API的简单工具。 When i'm sending tickets with attachments i use this code: 当我发送带附件的门票时,我使用以下代码:

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

And when i'm sending ticket without attachment I use this code: 当我发送没有附件的票时,我使用以下代码:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM