Created
December 8, 2023 16:03
-
-
Save neopheus/e4fe5ed6715a3b5a8c2528a5a2ff6577 to your computer and use it in GitHub Desktop.
Uber Eats Download Invoice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const delay = ms => new Promise(resolve => setTimeout(resolve, ms)); | |
const downloadInvoice = async (orderUUID) => { | |
try { | |
console.log(`Downloading invoice for order UUID: ${orderUUID}`); | |
const invoiceResponse = await fetch('https://www.ubereats.com/_p/api/getInvoiceFilesV1?localeCode=fr', { | |
method: 'POST', | |
headers: { 'Content-Type': 'application/json', 'x-csrf-token': 'x' }, // Remplacez 'x' par votre token CSRF réel | |
body: JSON.stringify({ orderUUID }), | |
}); | |
const invoiceData = await invoiceResponse.json(); | |
if (invoiceData.status === "success" && invoiceData.data.files) { | |
invoiceData.data.files.forEach(file => { | |
const a = document.createElement("a"); | |
a.href = file.downloadURL; | |
a.download = ""; // Le nom du fichier sera déduit de l'URL | |
document.body.appendChild(a); | |
a.click(); | |
window.URL.revokeObjectURL(a.href); | |
a.remove(); | |
}); | |
console.log(`Invoice for order ${orderUUID} downloaded.`); | |
} | |
await delay(1000); // Attente de 1 seconde entre chaque téléchargement | |
} catch (error) { | |
console.error('Error downloading invoice:', error); | |
} | |
}; | |
const fetchAllOrders = async (lastWorkflowUUID = '') => { | |
console.log('Fetching orders...'); | |
const res = await fetch('/api/getPastOrdersV1?localeCode=fr', { | |
method: 'POST', | |
headers: { 'Content-Type': 'application/json', 'x-csrf-token': 'x' }, | |
credentials: 'include', | |
body: JSON.stringify({ lastWorkflowUUID }), | |
}); | |
const { data } = await res.json(); | |
for (const order of Object.values(data.ordersMap)) { | |
await downloadInvoice(order.baseEaterOrder?.uuid); | |
} | |
console.log('Batch of orders processed.'); | |
if (data.meta?.hasMore) { | |
const lastOrder = Object.values(data.ordersMap).pop(); | |
await delay(5000); // Attente de 5 secondes avant de récupérer le prochain lot | |
return fetchAllOrders(lastOrder.baseEaterOrder?.uuid); | |
} else { | |
console.log('All orders processed and invoices downloaded.'); | |
} | |
}; | |
fetchAllOrders(); |
Author
neopheus
commented
Oct 18, 2024
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment