I need to make API calls from Airtable’s script editor and the endpoint requires Basic authentication with a base64 encoded string. The authentication format should be api:USERNAME:API_TOKEN encoded in base64.
Since btoa() is not available in Airtable, I found this alternative encoding solution:
I’m still getting 401 errors even after trying different encoding methods. I tested the same credentials with browser btoa() locally and copied the result directly, but that also returns 401.
Has anyone successfully implemented base64 encoding in Airtable for API authentication? What could be causing these authorization failures?
Been dealing with the same Airtable auth headaches for months. Your base64 setup looks good, but here’s what catches everyone - API providers format credentials completely differently. Don’t guess the format. Check their actual docs or just ask support what string format they want. Here’s what saved me: test your credentials outside Airtable first. Use Insomnia or throw together a quick Node.js script with btoa() encoding. If it works there but fails in Airtable with the same headers, you’re probably hitting IP restrictions or user-agent filtering. One more thing - some APIs are picky about header order or capitalization. I’ve seen APIs reject ‘authorization’ but work fine with ‘Authorization’. These tiny details will drive you crazy with HTTP auth.
Had this exact problem last month with a payment gateway API. Your encoding function looks good, but 401 errors usually mean the API endpoint has specific requirements.
First - drop the api: prefix from your credentials string. Most APIs expecting Basic auth just want USERNAME:TOKEN format. I’ve seen tons of misleading docs about this.
Also check if your API needs URL encoding for special characters in the username or token before base64 encoding. Some tokens have characters like + or / that need escaping first.
Quick debug tip - log your final Authorization header value and test it directly with curl or Postman outside Airtable. If it works there but fails in Airtable, you’re probably hitting CORS restrictions or the API blocks certain user agents.
One more thing - some APIs are picky about request timing or need additional headers like Accept: application/json. The 401 might not be auth failure but missing headers the API considers part of authentication.
Your base64 encoding looks fine - the issue’s probably elsewhere. I’ve hit similar 401 errors with Airtable and other APIs, and they can be picky about auth formats. Double-check your credentials match exactly what they want - some APIs expect username:password, others need api_key: with a blank password. Make sure your token hasn’t expired or been regenerated recently. Also watch out for missing headers like Content-Type: application/json (some APIs want this even on GET requests) and case-sensitive Authorization headers. Try logging your encoded string and comparing it character-by-character with btoa() output in your browser console to rule out encoding problems.
Hit this same issue yesterday with Shopify’s API. Drop the api: part completely - basic auth usually just wants username:token. Also check if you need the raw secret key or some encoded version they give you. Sometimes they hand you a “display token” that’s already processed, so don’t encode it twice. Your base64 function looks fine though.
I hit the same issue with third-party APIs in Airtable scripts. That 401 error probably isn’t your base64 code - it looks fine. Some APIs are picky about the auth string format. You’re using api:USERNAME:API_TOKEN but many want just USERNAME:API_TOKEN or API_TOKEN: with no username. Watch out for trailing spaces or hidden characters in your credentials too - I’ve copied tokens with invisible whitespace that broke everything. Try hardcoding simple test credentials first to see if it’s encoding or credential format. Also check if the API needs extra headers like User-Agent or API version - Authorization alone isn’t always enough.