Create A Data Storage Point


Storage allows you to securely store your data used in scripts on our servers. You can keep your data out of the Airtable scripting environment, organized, reusable, and non-accessible to others.

Learn more about On2Air: Storage



In this article:

Create a New Data Storage Point
Create an Access Key
Access Links in Your Script
Query and Retrieve Your Data in Airtable
Output as an Object
Combine Multiple Keys in One API Call
Update Your Data
Storage Data Settings

Create a New Data Storage Point

Click Create New Data

Name your Data Item in the name field

Click out of the name field and your Data Code will automatically be generated to match your data name

Enter the data your need to store in the text box

This can be formatted as JSON or plain text

Add a description of your data

Click Update Data

After creating a data storage point, you need to generate an Access Key.



Create an Access Key

Select the Keys tab in your data item

An access key is automatically generated

The key defaults to both Write and Read Access
If you prefer, you can set it to Read-only by toggling the Read-only switch

You can generate as many Keys as needed



Once you have created a Storage data point and an Access Key, you will use the Data Code and Access Key in your script to interact with your data.



Data Code



Access Key

Access Links to Use in Your Scripts

Read and Write links are automatically generated once you have a Data Code and an Access Key.

Select the Links tab in your data item

Select the Key you want to use
You will be able to see whether the key is Read/Write or Read Only

The URL will be automatically copied to your clipboard when clicked

The Read URL allows you to perform GET requests to retrieve the data stored in your data point.

The Write URL allows you to perform POST requests to this URL to update the data stored in your data point.





URL Automatically Generated with Data Code and Access Key

How to Query and Retrieve Your Data in Airtable

If you haven't used the Scripting Block in Airtable, learn how to add code to the Scripting Block.

If you are using On2Air: Scripts

Add your script as a new Script and create a Block to add to your base Scripting Block

Learn more about Scripts and Blocks

If you are not using On2Air: Scripts

Add your script to your base Scripting Block directly in Airtable

Add the following lines of code to retrieve your data

Use fetch() with the corresponding URL

res = await fetch('https://storageapi.o2adev.com/api/storage/get/my_personal_info:tfxA2HUB')

Return data as JSON string

name = await res.json()

Input your data code

const name = answer[‘data’][your_data_code]

Output

output.inspect(name)

Final

// Storage Data
// Perform Query

let res, answer
res = await fetch('https://storageapi.o2adev.com/api/storage/get/my_personal_info:tfxA2HUB')
answer = await res.json()
const secret = answer['data']['my_personal_info']
output.markdown('## Get Secret')
output.inspect(secret)






To output as an object

Add JSON.parse

name = JSON.parse(name)

In this example, config_data is the Data Code from your Storage data.

Final

//Output as JSON

let res, answer
res = await fetch('https://storageapi.o2adev.com/api/storage/get/config_data:TVl9CCap')
answer = await res.json()
let config = answer['data']['config_data']
output.markdown('## Get Config Data')
output.inspect(config)
config = JSON.parse(config)
output.markdown('## Config Data after parse')
output.inspect(config)




Combine Multiple Keys in One API Call

You can use 1 API call to get multiple data points.

In the URL, add a comma (,) between each Data Code and Access Key combination
      Data_Code:AccessKey, Data_Code:AccessKey

res = await fetch("https://storageapi.o2adev.com/api/storage/get/Data_Code:DataKey,Data_Code:DataKey")

In this example, my_personal_info:tfxA2HUB and config_data:TV19CCap are Storage Data points.

my_personal_info and config_data are the Data Code and tfxA2HUB and TV19CCap are the Access Key.

res = await fetch('https://storageapi.o2adev.com/api/storage/get/my_personal_info:tfxA2HUB,config_data:TVl9CCap')

Final

// Get Multiple Keys

let res, answer
res = await fetch('https://storageapi.o2adev.com/api/storage/get/my_personal_info:tfxA2HUB,config_data:TVl9CCap')
answer = await res.json()
output.markdown('## Get Multiple Keys')
output.inspect(answer)




To update your data

You can change or update the data in your storage point directly from the script.

Copy the URL from your data point in Storage
It will have update instead of get in the URL

res = await fetch('https://storageapi.o2adev.com/api/storage/update/my_personal_info:tfxA2HUB,config_data:TVl9CCap'

Add your new data

const body = {
data: {
my_personal_info: 'new secret value',
config_data: {new:'data'}
}
}


Add the method as POST

method: 'POST',

Add the body as JSON.stringify(body)

body: JSON.stringify(body),

Add the header to read as JSON

headers: { 'Content-Type': 'application/json' }

Final

// Update Data

let res, answer
const body = {
data: {
my_personal_info: 'new secret value',
config_data: {new:'data'}
}
}
res = await fetch('https://storageapi.o2adev.com/api/storage/update/my_personal_info:tfxA2HUB,config_data:TVl9CCap',{
method: 'POST',
body: JSON.stringify(body),
headers: { 'Content-Type': 'application/json' }
})
answer = await res.json()
output.markdown('## Update Response')
output.inspect(answer)


If any of your Storage data points in your URL are read-only, you will receive a status of Unauthorized for that data point. Any other data points with Read/Write access will still update. 

Storage Data Settings

Delete Data

If you no longer want a Storage Data Point, select Delete Data

Verify deletion by selecting, Yes, I want to delete this data pair

         WARNING: Deleting a data pair cannot be undone

Was this article helpful?
Cancel
Thank you!