We have a need to retrieve the ticket attachment in our ticket details app so we can send it to a different page. We retrieve the ticket data by using the data methods. We do receive the data but when we actually do a GET request to the ticket attachment url we receive the error: No ‘Access-Control-Allow-Origin’ header is present
The strange thing is that this works for one FD account but not for two other accounts. Could it be that the CORS related response headers are different per hosting region? Or perhaps the older accounts run on an older configuration and that is why the response header is missing?
we retrieve the ticket data using: window.client.data.get(“ticket”)
an actual handler is implemented in the real code
then we get the attachment content using this script:
var xhr = new XMLHttpRequest();
xhr.open(“GET”, attachment.attachment_url, true);
xhr.responseType = “blob”;
xhr.onload = function (e) {
var reader = new FileReader();
reader.onload = function (event) {
var res = event.target.result;
let encodedItem = new Object();
encodedItem.id = attachment.id;
encodedItem.encodedString = res;
encodedItem.name = attachment.name;
encodedItem.size = attachment.size;
encodedArrayItem.push(encodedItem);
if (count == ticketAttachment.length) {
window.appLocal.globallyEncoded = encodedArrayItem;
}
}
var file = this.response;
reader.readAsDataURL(file)
};
xhr.send()
Thanks for your patience while we tried to figure out a solution.
As you have tried multiple approaches, this being a front-end app will result in a CORS error. And one way to overcome this is with a Request method or having an SMI in a Serverless component but due to restrictive content-type it is not possible with that.
Thank you for looking into this. If I would use the SMI then how would I get the ticket attachment data back to the ticket app? The response is strictly JSON so would I have to convert the ticket attachment to some sort of Base64 string and put that into the JSON? Are there restrictions to this?
The response is strictly JSON so would I have to convert the ticket attachment to some sort of Base64 string and put that into the JSON?
This would have payload restrictions.
I remember that you wanted to download the image so that you could send it to another API. Would downloading the image and sending it to the API in SMI help?
I was able to retrieve the attachments with a server component and pass it to the frontend component as a Base64 string. BUT, it seems there is another issue.
I can retrieve the ticket attachments if they were added manually in Freshdesk, but attachments of a ticket that was created because of an inbound mail CANNOT be retrieved. It then gives a HTTP 403.
There is a clear difference in the domain where the file is stored. See below
Attachment URL of ticket created via mail, this gives HTTP 403 when navigating to it:
That’s great to know using SMI and returning data as Base64 worked. Can you give more details so that it would help others who are trying to build the same? Thanks!
I see the difference in links in terms of how and where they are being stored. Let me try to get you help in terms of that.