3 Save data to Airtable

Watch the video tutorial

import os
from flask import Flask, request
from dotenv import load_dotenv
from pyairtable import Table
import json


api_key = os.getenv('AIRTABLE_API_KEY')
base_id = os.getenv('AIRTABLE_BASE_ID')
table_name = os.getenv('AIRTABLE_TABLE_NAME')

app = Flask(__name__)

@app.route('/')  # this is the home page route
def hello_world():  # this is the home page function that generates the page code
    return "Hello world Airtable!"

def save_to_db(req):
        session_info = req.get('sessionInfo')
        name = session_info.get('parameters').get('person').get('name')
        email = session_info.get('parameters').get('email')
        url = session_info.get('parameters').get('url')

        table = Table(api_key, base_id, table_name)
        result = table.create({'Name': name, 'Email': email, 'Website': url})
        return 'Thanks. We will be in touch soon.'
    except Exception as e:
        error_str = str(e)
        return 'Something went wrong. Please try again later'

@app.route('/webhook', methods=['POST'])
def hello_webhook():
    req = request.get_json(silent=True, force=True)
    with open('data.json', 'w', encoding='utf-8') as f:
        json.dump(req, f, ensure_ascii=False, indent=4)
    result = save_to_db(req)
    jsonResponse = {
                "messages": [
                        "text": {
                            "text": [
    return jsonResponse

if __name__ == '__main__':
    app.run(host='', port=8081)