Fetch request blocked by CORS when tried to upload side conversation file by API | Community
Skip to main content

Fetch request blocked by CORS when tried to upload side conversation file by API

  • January 11, 2023
  • 1 reply
  • 0 views

Hi there,

I'm facing a problem while I've tried to upload an attachment by my javascript code using fetch request.

I've inserted my file inside FormData (as said in documentation) and tried to send it by me following code:

const formData = new FormData();

formData.append('file', e.target.files[0])

const request = await fetch(`https://<instance>.zendesk.com/api/v2/tickets/side_conversations/attachments`,

{
method:"POST",
body:formData,
headers: {
'Authorization':'Basic encoded(email/token:token)',
},

}

);

const response = await request.json();

I'm able to upload files to "/api/v2/uploads.json", using fetch request and I don't catch a error.


1 reply

Tipene
  • January 12, 2023

Hi @vinicius13,

If you're making client side requests to the Zendesk API, you will need to use OAuth for your authorization in most cases. Here's a couple links to the documentation which go in to a bit more detail:

Making cross-origin, browser-side API requests

How can I troubleshoot CORS?

I hope this helps!

Tipene