-
Setup Airtable
Create a new base named
Submissions
and create a table with three columns, "Name", "Email", and "Message". -
Get Airtable Credentials.
There are 2 environment variable you'll need to add your project to properly run the example:
AIRTABLE_KEY
: Get Airtable API Key. Airtable DocsAIRTABLE_DB
: Get the ID for the "Submissions" Base in interactive Airtable API docs. Airtable Docs
You'll want to add these as environment variables when deploying to Gatsby Cloud. Don't forget to add them to the Preview variables if you plan to add a CMS preview integration.
-
Start developing.
To get started, run
npm install
to add all necessary packages.When developing locally, you'll want to include the ENV variables in your
.env.development
. Read more about how Gatsby handles.env
files and environment variables in the Gatsby Docscd examples/functions-airtable-form npm install npm run develop
-
Open the code and start customizing!
Your site is now running at http://localhost:8000! You can use the UI on the index page to test the functions or directly access them at http://localhost:8000/api/airtable
For this route, hitting the route with a POST request with the following body should submit a form response to your Airtable base:
{ "name": "Sample Name", "email": "sample@example.com", "message": "Hello, World!" }
Edit
src/pages/index.js
to see your site update in real-time! -
Deploy
You can deploy this example on Gatsby Cloud by copying the example into a new repo and connecting that to Gatsby Cloud.