download and open pdf link with bearer authentication

Hi,
i need help to download and open PDF URL using bearer authentication from 3rd party
method : ‘get’ ,
headers : {
‘Content-Type’ : ‘application/pdf’ ,
“Authorization” : "Bearer " + secret ,
}
i’m getting ok,200 on the backend but how can i open the pdf on the frontEnd if i can only run the fetch from the backend?

Read the 3rd party’s documentation and see how’s the response is structured.
Maybe you get the file URL in the response body (which you an get by running response.json() ), but you should read the docs.

its to get JSON
i know how to work with JSON
but here i need it to open PDF like you clicking on a link that open PDF but with authentication :frowning:

I’m not sure I got your question:
After you got the file pdfURL, why wouldn’t you just use wixLocation.to (pdfURL)

@jonatandor35 but i need to add to the header “Authorization” : "Bearer " + secret ,
an i can add it only via fetch API
but it run only from the backend
if i’m runing it on the frontend i getting CORS issue

@naimibaby Hi,
First of all, if you put it in jsw file (and not .js file) you can return the fetch result from the backend to the frontend.
Second, the CORS settings depends on the 3rd party. Read their docs and see if and how to it directly from the frontend.

@jonatandor35 Hi and thank you for your help,
i have trying from jsw in the backend
i have got the response on the frontend
and have print it to the console
but now how i can download or popup the pdf from the response(body)?
when i using the postman on my pc its show me the body as an image