ERROR: btoa is not defined

Hi everyone,

I am trying to automate an SMS using a basic Twilio script that I found here:
Twilio Script

This script works when I run it within the script app, even with my changes made to disable to input text. When I run the same code in the automation run script action I get the error code ‘ReferenceError: btoa is not defined’.

My code is below:

* Twilio send SMS script
 * Send a single SMS to a provided telephone number using the Twilio service
 * The Airtable "Send SMS" Block (available to customers with a "Pro" account)
 * is capable of sending many messages in batches based on the contents of the
 * Airtable Base in which it is installed.
 * **Notes on adapting this script.**
 * The script prompts for input every time it is run. For some users, one or
 * more of these values may be the same with every execution. To streamline
 * their workflow, these users may modify this script by defining the constant
 * values in the first few lines. The values should be expressed as JavaScript
 * strings in the object named `hardCoded`.
'use strict';

 * Users may provide values for any of the properties in the following object
 * to streamline the script's startup.
const hardCoded = {
    twilioAccountSid: 'XXX',
    twilioSendingNumber: 'XXX',
    // Note: the code in Airtable scripts is visible to all users of the
    // Airtable base. By entering the Twilio Auth Token here, all users will
    // have access to that sensitive information.
    receivingNumber: 'XXX',
    messageBody: 'XXX',
    twilioAuthToken: 'XXX'

const twilioAccountSid =
    hardCoded.twilioAccountSid || (await input.textAsync('Twilio Account SID'));
const receivingNumber = hardCoded.receivingNumber;
const messageBody = hardCoded.messageBody;
const twilioSendingNumber =
    hardCoded.twilioSendingNumber || (await input.textAsync('Twilio sending telephone number'));
const twilioAuthToken = hardCoded.twilioAuthToken || (await input.textAsync('Twilio Auth Token'));

const url = `${twilioAccountSid}/Messages.json`;
const headers = {
    // Format the "Authorization" header according to "HTTP Basic Auth"
    Authorization: `Basic ${  btoa(`${twilioAccountSid}:${twilioAuthToken}`)}`,
    // Twilio expects request data to be formatted as though it were submitted
    // via an HTML form
    'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
const body = new URLSearchParams({
    From: twilioSendingNumber,
    To: receivingNumber,
    Body: messageBody

let result;

try {
    let response = await fetch(url, {
        method: 'POST',

    if (!response.ok) {
        result = `Error sending SMS: "${await response.text()}"`;
    } else {
        result = 'SMS sent successfully.';
} catch (error) {
    result = `Error sending SMS: "${error}"`;


Can anyone provide me with some help here?

Thank you

Welcome to the Airtable community.

You have run into one of the differences between scripting app and automation action scripts. You can’t use btoa in an action script. No idea why.

You can run the btoa conversion in scripting app, output the resulting string, and substitute that in place of the btoa in this automation script.

1 Like

Welcome to the community, @Nicholas_Payne! :smiley: If @kuovonne’s answer solved your problem, please mark her comment as the solution to your question. This helps others who may be searching with similar questions. Thanks!

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