0

What I'm trying to do: my endpoint returns a client data and provide the ability to return data changed from the last call. So I need to store timestamp and something like a hash of the request - so next time I'll provide it and receive only the newest data.

For those purposes, I'm going to use StoreClient a built-in utility. But as I understand it will operate secret value to access my stored data. And if clients will create few Zaps with my app, which use the same secret - their data won't be separated and as a result, I'll have issues.

I decided to use secret+ZapId for that, seems logical, but as I understand it is not accessible.

For REST hooks it is possible to get Zap Id inside subscribing hook - but that's completely different and not suitable for my case.

Questions:

  1. How I can get zap id programmatically?
  2. Is it the correct way to use StoreClient in such a case?
Vasyl
  • 236
  • 2
  • 12
  • Zapidn is only available in the `performSubscribe` and `performUnsubscribe` methods. In above 2 methods you can get Zap Id using `bundle.meta.zap.id`. Here is the more info https://github.com/zapier/zapier-platform-cli#bundlemeta – Kishor Patidar Jan 03 '20 at 18:11

1 Answers1

0

The Zapier developer platform has just the feature for this use case: z.cursor (docs).

The idea is that you can store arbitrary data that persists across trigger runs. The zapier platform takes care of scoping data to each individual zap.

Here's a rough example (copied from the docs):

const perform = async (z, bundle) => {
  let cursor = await z.cursor.get(); // string | null;

  const response = await z.request(
    'https://someEndpoint',
    {
      // if cursor is null, it's sent as an empty query
      //   param and should be ignored by the server
      params: { cursor: cursor }
    }
  );

  // we successfully got page 1, should store the cursor in case the user wants page 2
  await z.cursor.set(response.nextPage); // you would hash whatever data you want to store

  return response.items;
};
xavdid
  • 5,092
  • 3
  • 20
  • 32
  • Thanks. Yep, that's something close, but as I understand `Cursors are stored per-zap and last about an hour.` So if zap will be not triggered more than hour - my data will disappear. That's a handy thing for dealing with pagination. But not sure if it can serve my needs. – Vasyl Jan 08 '20 at 14:20
  • are you using this functionality in a trigger? it's also worth noting that you don't need to worry about sending duplicate data to Zapier- it does [deduplication](https://platform.zapier.com/legacy/dedupe) for you. – xavdid Jan 08 '20 at 19:12