zapierzapier-cli

Zapier StoreClient undefined


I'm trying to store state between calls similar to the documentation here: https://zapier.com/apps/code/help#code-examples

However, I try to run the code from a Zap, I get:

StoreClient is not defined

The documentation states that I shouldn't have to require anything to use StoreClient: "There is no need to require it - it comes pre-imported in your Code environment."

I'm on the latest version of zapier-platform-core (8.3.0). I'm using the exact code from the example linked above.

 const count = await store.get('some counter')
 const newCount = (count || 0) + 1;
 await store.set('some counter', count);
 return {count: newCount};

Solution

  • David here, from the Zapier Platform team. Great question!

    This is a little bit unclear based on the docs - StoreClient is only available in the Code app (aka Code by Zapier). If you're using zapier-platform-core, you're creating a cli app, which is a vanilla node.js environment. If you want to interact with Storage by Zapier from within a cli app, you can use the docs on the site: https://store.zapier.com. Namely:

    {
      "how does it work?": {
        "always provide either `?secret=12345` or `X-Secret: 12345`": "",
        "GET /api/secret": [
          "will return a random secret for you to use if you need one."
        ],
        "GET /api/records": [
          "will return a full object of all values stored by default.",
          "you can also specify only the keys you want via the",
          "querystring like`?key=color&key=age`."
        ],
        "POST /api/records": [
          "provide a body with a json object with keys/values you want",
          "to store like `{\"color\": \"blue\", \"age\": 29}`."
        ],
        "DELETE /api/records": ["completely clear all the records in this account"],
        "PATCH /api/records": [
          "A data with a particular schema needs to be received.",
          "The schema specifies which action to do and with what parameters.",
          "For example {\"action\": \"increment_by\", \"data\": {\"key\": \"<key_name>\", \"amount\": 1}} to increment the value specified by \"key\"."
        ]
      }
    }
    
    

    Requests to those endpoints can be made using the standard z.request, which is well-documented here: https://github.com/zapier/zapier-platform/tree/master/packages/cli#making-http-requests