Retrieve and process all entries from Zapier's data storage

I’m working with Zapier’s data storage and I need help getting all the stored information. Here’s what I’ve got so far:

const dataStore = StorageClient('mysecretkey');
const singleItem = await dataStore.fetchOne('somekey');
console.log({output: singleItem});

This code works fine for getting one item, but I want to grab everything and go through it all. I tried using dataStore.pop_list(key), but that didn’t work because the data isn’t stored as lists.

The data in the storage looks like it has main keys with sub-values. I’m not sure how to loop through all of these and process them. Any ideas on how to get all the keys and their values from the storage? I’m pretty stuck and could use some help figuring out the right approach.

Thanks in advance for any suggestions!

I’ve encountered this issue before when working with Zapier’s storage. While the previous suggestions are valid, I found a more efficient method using the fetchAll() function. Here’s a streamlined approach:

const dataStore = StorageClient('mysecretkey');
const allData = await dataStore.fetchAll();

for (const [key, value] of Object.entries(allData)) {
  // Process each key-value pair here
  console.log(`Key: ${key}, Value:`, value);
}

This method retrieves all data in one go, reducing the number of API calls. It is particularly useful for larger datasets. However, be cautious with memory usage if you’re dealing with an extensive amount of data. In such cases, consider implementing pagination or chunking to mitigate potential timeout issues.

I’ve been in a similar situation with Zapier’s data storage, and I found a workaround that might help you out. Instead of trying to fetch everything at once, I ended up using a combination of listKeys() and fetchOne() in a loop.

Here’s what worked for me:

const dataStore = StorageClient('mysecretkey');
const allKeys = await dataStore.listKeys();
const allData = {};

for (const key of allKeys) {
  const value = await dataStore.fetchOne(key);
  allData[key] = value;
}

console.log(allData);

This approach lets you build up an object with all the keys and their corresponding values. It’s not the most efficient for large datasets, but it gets the job done for most use cases. Just be mindful of any rate limits or timeout issues if you’re dealing with a massive amount of data.

Once you have all the data in the allData object, you can easily process it however you need. Hope this helps!

hey lucasg, have you tried using dataStore.listKeys() to get all the keys first? then you could loop through those and use fetchOne for each key. something like:

const keys = await dataStore.listKeys();
for (const key of keys) {
  const item = await dataStore.fetchOne(key);
  // process item here
}

might work? let me know if that helps!