Tool Template

Airtable Get Records

by Webble Templates

Use Template
/**
 * @param {object} args
 * @param {string} args.apiToken
 * @param {string} args.baseId
 * @param {string} args.tableId
 * @param {string} args.viewId The name or ID of a view in the table. If set, only the records in that view will be returned.
 * @param {number} args.pageSize The number of records returned in each request. Must be less than or equal to 100. Default is 100.
 * @param {number} args.maxRecords The maximum total number of records that will be returned in your requests. If this value is larger than pageSize (which is 100 by default), you may have to load multiple pages to reach this total.
 * @param {string} args.offset The offset value from the previous request. Use to fetch records for the next page.
 * @param {string} args.filterByFormula
 */
async function main(args) {

  const searchParams = new URLSearchParams()

  if(args.pageSize) searchParams.set("pageSize", args.pageSize);
  if(args.maxRecords) searchParams.set("maxRecords", args.maxRecords);
  if(args.offset) searchParams.set("maxRecords", args.offset);
  if(args.filterByFormula) searchParams.set("filterByFormula", args.filterByFormula);

  const result = await fetch(`https://api.airtable.com/v0/${args.baseId}/${args.tableId}?${searchParams.toString()}`, {
    method: "GET",
    headers: { "Authorization": `Bearer ${args.apiToken}` }
  }).then(res => res.json())

  return {
    output: result
  }
}

Want to see more chatbot templates and resources?

View more templates