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