Help

Twilio and Airtable: Need help updating a field with Airtbale Node.JS

Topic Labels: API
1702 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Raymond_Stamper
5 - Automation Enthusiast
5 - Automation Enthusiast

I am wrote code (below) inside a Twilio function which utilizes the Airtable API which first looks up a record in specific table (“clients”) in an Airtable base. It then pulls field data from that record (using record.get), and then using JSON in the “Callback”, enables me to utilize that field data later on in my Studio flow. It works perfectly.

What I’m trying to figure out now is how to reverse that procedure. I’d like, once again, to first find the Airtable record. But then, instead of using “record.get” to pull field data in; I would like to write/update​ fields back into that Airtable record.

In other words, after the line that reads:

“if (record.get(“Client_ID”) === clientnumber)”

instead of the two record.get commands that pull data from the fields, what would the code be to write data (say just a literal string) back to those two fields?

Thanks in advance for any help you might provide!


My Function Code to Fetch Airtable Data Into My Studio Flow

const airtable = require(“airtable”);
const twilio = require(“twilio”);

exports.handler = function (context, event, callback) {
const base = new airtable({
apiKey: context.AIRTABLE_API_KEY,
}).base(context.AIRTABLE_BASE_ID);
const clientnumber = event.clientphone;

return base(“Clients”)
.select()
.all()
.then((records) => {
records.forEach((record) => {
if (record.get(“Client_ID”) === clientnumber) {
const bussname = (record.get(“Business Name”));
const email1 = (record.get(“NEmail1”));
callback(null,{“business”:bussname,“remail1”:email1});
}
});
})
.catch((error) => {
callback(error);
});
};

1 Reply 1
J_Mai
5 - Automation Enthusiast
5 - Automation Enthusiast

Don’t you just need to use the Update Record on the Airtable API?

Also - might help to use ``` to format your code when copying and pasting snippets. Just a suggestion hope that helps.