Uploading a file for a Request



2023년 9월 27일에 게시됨

Currently coding in C# and I am having trouble figuring out how to attach a token returned from Uploads API to a new Request. I have two service methods that have been tested on Postman and work as expected on their own; RequestTicket and UploadAttachment. RequestTicket allows an end user to make a ticket request by calling the /api/v2/requests endpoint using Request API and UploadAttachment calls the /api/v2/uploads endpoint to get the upload token. 

public async Task<string> RequestTicket(string comment)
        {
            // Construct the ticket payload and the request URI
            var zendeskTicket = new TicketSSO(comment, _userResolver.CurrentStaff);

            var requestUri = $"{_zendeskClientConfig.Url}/requests";

            // Create the request message for POSTing the ticket to Zendesk
            _zendeskHttpRequest.CreateRequestMessage(HttpMethod.Post, requestUri, zendeskTicket.BuildJsonRequest());

            // Send the request
            var response = await _zendeskHttpClient.SendAsync(_zendeskHttpRequest);
            return response;
        }

public async Task<string> UploadAttachment(string filePath, string fileName)
        {
            // Create the file payload
            var file = new UploadSSO(filePath);

            // Construct the request URI for uploading an attachment
            var requestUri = $"{_zendeskClientConfig.Url}/uploads.json?filename={fileName}";

            // Create the request message for POSTing a new file upload
            _zendeskHttpRequest.CreateRequestMessage(HttpMethod.Post, requestUri, file.BuildJsonRequest());

            // Send the request and upload an attachment
            var response = await _zendeskHttpClient.SendAsync(_zendeskHttpRequest);

            Console.WriteLine("Response: ", response);

            return response;
        }

0

2

댓글 2개

Greg Katechis Thank you for getting back to me so quick! I apologize but I am not sure what you mean by attaching it to the comment but not the ticket, how can I attach a file to a request if it hasn't been created yet? The article you provided seems to be talking about a ticket and I am working with the Request API. I am trying to allow my end users to attach a file when they initially create a request not just when they comment on an already existing ticket.

0


Hi Luis! The reason that you're running into this issue is because you need to add the attachment to a comment and not the ticket itself. In your case, you're attempting to add this during the request, which won't work. We outline that in this article, which can provide some additional reference points for you. 

Let us know if you have any questions about this!

0


로그인하세요.

원하는 정보를 못 찾으셨나요?

새 게시물