Integrating Twilio Studio with Airtable - Storing chatbot responses in database

I’m working on a chatbot project using Twilio Studio and need to save user responses to an Airtable database. I’m not very experienced with coding, so I followed an online tutorial but can’t get the function to work properly.

Here’s my current function code:

exports.handler = function(context, event, callback) {

let userInfo = {
    fullName : event.fullName,
    userEmail : event.userEmail,
    timestamp : Date.now()
};

var Airtable = require('airtable');
var database = new Airtable({apiKey: context.AIRTABLE_API_KEY}).base('appXYZ123ABC456DEF');

database('Users').create(userInfo, function(error, newRecord) {
    if (error) { console.error(error); return; }
    console.log(newRecord.getId());
    callback(null, userInfo);
});

};

When I test this with Postman, I get errors in the Twilio Console and the data doesn’t save to my Airtable base. My Airtable has these fields: Id, fullName, userEmail, and timestamp.

I’m also wondering if I should use the HTTP Request Widget in Twilio Studio Flow instead, but I’m not sure how to set it up correctly. Has anyone successfully connected Twilio Studio to Airtable before? What am I missing here?

Had the same issue connecting Twilio Functions to Airtable last year. Usually it’s your API key setup in the Twilio environment variables. Check that AIRTABLE_API_KEY is set correctly under Dependencies & Environment Variables - it should start with ‘key’ plus your token. Timestamp format got me too. Airtable’s picky about dates. Use new Date().toISOString() instead of Date.now() since Airtable wants a date string, not a number. Also check your base permissions in Airtable. Your API key needs write access to whatever base you’re hitting. Test with a direct API call to Airtable first to rule that out. Twilio Console error messages will tell you what’s actually breaking. 401 = auth problems, 422 = field validation issues.

Had this exact issue a few months back when building a customer feedback bot. Your function looks mostly right, but there’s a couple gotchas.

First - you’re not handling the callback in the error case. When there’s an error, you need to call the callback to tell Twilio what happened:

if (error) { 
    console.error(error); 
    callback(error);
    return;
}

Second - check your Airtable field names match exactly what you’re sending. The “Id” field in Airtable is usually auto-generated, so don’t include it in your userInfo object.

Make sure your base ID is correct (the appXYZ123ABC456DEF part) and your table name is exactly “Users”.

For the HTTP Request Widget approach - honestly, stick with the Function. It’s more reliable and gives you better error handling. The HTTP widget works but you lose control over the process.

What helped me debug was adding more logging:

console.log('Received event data:', event);
console.log('Attempting to save:', userInfo);

Check your Twilio Console logs after testing. They’ll show you exactly what error Airtable’s returning.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.