I have a trigger from a third-party source for tracking “Downloads”, but the id it returns is for the object downloaded, not the download itself, and is therefore not always unique.
I initially implemented code to append the download timestamp to make it unique, but I just ran into a scenario where the a file got downloaded multiple times at the exact same time (I’m baffled this is even possible) and I am therefore looking for another way of making each result unique regardless of the id and/or timestamp returned. I am thinking there may be a way for automatically appending a numeric value to each result which increments over time (though not sure how Zapier would be able to track what the last value is...). It’s ok if the value resets on each poll as that would still prevent duplicate results.
Appreciate any suggestion anyone may have to solve that problem.
Disclaimer, I am not a developer :)
Current code for reference:
const options = {
url: 'https://api.X.com/v3/downloads',
method: 'GET',
headers: {
'Accept': 'application/json',
'API-Key': bundle.authData.client_id,
'Authorization': `Bearer ${bundle.authData.access_token}`
},
params: {
'page': bundle.meta.page + 1,
'page_size': 100,
'company_downloads': true,
'date_from': bundle.inputData.date_from
}
}
return z.request(options).then((response) => {
response.throwForStatus();
const results = response.json;
const downloads = resultsn"downloads"].map((item) => {
const id = `${item.id}.${item.date_downloaded}`;
return Object.assign(item, {
id,
_id: item.id, // Real item id
});
});
console.log(downloads);
return downloads;
});