I am trying to insert API of CloudConvert but I didn't run it. I have got a 401 error.
I have a function that create a excel (.xlsx) but when I click this function, I want to convert to .pdf format. How can I do?
My codes: `
kontrat.on("click", function () {
var sablon = butun_veriler.nesne.features[0].properties.kiralik_nesne_turu + "_kontrat";
var sid = veri.features[0].properties.id;
var rapor_url = kd_islemcisi.genel_url(gorunen_kullanici_adi, sablon, "v_kira_sozlesme", "sozlesme_id=" + sid, sid);
// Dönüşüm işlemi için gereken verileri oluşturun
const apiKey = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIxIiwianRpIjoiY2U4ZjIzNTA5ODkwMGZhYWEzNjczZjc2YjEzOTQwMzk3ZGYzNGZkYTI5OWYxZTc2ODRlODdiNWRkOWI1YzBkNDlkNGM3MWYzZjBkNDExZDciLCJpYXQiOjE2OT'; //
const apiUrl = 'https://api.cloudconvert.com/v2/convert';
// Dönüşüm işlemi için gereken verileri oluşturun
const requestData = {
apikey: apiKey,
inputformat: 'xlsx', // Girdi formatı (Excel)
outputformat: 'pdf', // Çıktı formatı (PDF)
file: rapor_url, // Excel dosyasının URL'si
};
// API isteği gönderin
fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(requestData),
})
.then((response) => response.json())
.then((data) => {
// Dönüştürülen PDF dosyasının URL'sini alın
console.log(data)
const pdfUrl = data.data.url;
// PDF dosyasını indirme bağlantısını oluşturun veya görüntüleyin
window.open(pdfUrl, '_blank');
})
.catch((error) => {
console.error('Dönüşüm hatası:', error);
});
});`