Use Key-Value Store

Learn how to use Key-Value Store

Purpose

We can use KV Store to store basic state between action runs or to help us centralize values we need across actions, like IDs. Note that KV Store items are always stored as strings, so you may have to cast the type.

Usage Examples

We can store our Airtable base ID, Google Sheets ID, or any other ID in KV Store so that we don’t have to copy/paste it into our actions. If we change the ID, we just change it in one location. You can set a KV store value in the “Key-Value Store” tab, then call it in your action with the following code:

const base_id = kv.get("AIRTABLE_BASE_ID") // Returns the item from KV store

You can also set values in KV store. If the value does not exist in KV store then it will be created the first time the code is run. For example:

kv.set("highScore", 500) // This will update "highScore" to "500" (string value)

Prompting Tips

When you want our AI to generate code for you with KV store, mention that you want to use KV store like this:

Use KV Store to fetch the Airtable base ID. I called it AIRTABLE_BASE_ID.

Last updated