CORS issue with Upload / Request API and no file attached



Publicado 06 abr 2021

Hi,

I've tested the CURL snippet written below and it all works well, but I have an issue when I try to translate that in jsx code for react/axios api calls.

curl "https://<removed>.zendesk.com/api/v2/uploads.json?filename=test-image.png" \ -v -u <removed>/token:<removed> \ -H "Content-Type: application/binary" \ --data-binary @test-image.png -X POST

How should the above code be written to send an uploaded file to the zendesk dashboard?

With the code written below, I get a CORS issue. I've tried to add 'Allow origin * .... ' to the Headers, but no luck.

Do I need to use the username/token in the upload object to avoid CORS or it's not necessary? Also, I've tried with Postman and when I check the ticket in the ZendDesk dashboard, there is no attachment. Am I missing something?

 

axios.post(`https://<removed>.zendesk.com/api/v2/uploads?filename=${this.state.selectedFileName}`,
this.state.selectedFile
{
  headers: {
    accept:'application/json',
    'Content-Type':'application/binary',
  },
})
.then(res => {
    axios.post("https://<removed>.zendesk.com/api/v2/requests.json", {
    headers: {
      accept:"application/json",
      "Content-Type":"application/json",
    },
    request: {
       requester: {
          name:this.state.fields.name,
       },
       subject:this.state.fields.job + " Position",
       recipient:"help@<removed>.com",
       group_id:<removed>,
       comment: {
         body:this.state.selectedFile,
         upload: [`${res.data.upload.token}`]
       },
      } ...... not important ...
});

 

 

 

 

 

 

 

 


0

6

0 comentarios

Iniciar sesión para dejar un comentario.

¿No encontró lo que buscaba?

Nueva publicación