Help

Data from API call not returning to Postman

593 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Colin_Maretsky
4 - Data Explorer
4 - Data Explorer

I used the API template code provided by Airtable, which includes a console.log of my data. That data is consoled just fine for me, but its not being returned to Postman (from where I made the call).

The request in Postman takes up to one minute before timing out, with the “ERR: socket hang up” error.

So I can only assume that I’m not properly returning the data in my function, but I’m at a loss, having tried returning it in every variation. Below is my function:

(The return is inside the .forEach method, but I’ve also put it within the page function, and also wrapped the whole await base in a variable which I then returned at the end of the getStudent function. I also treid async/awaiting it).

var Airtable = require('airtable');
require('dotenv').config();
const { API_KEY } = process.env;
var base = new Airtable({ apiKey: API_KEY }).base('app8ZbcPx7dkpOnP0');

const minifyRecord = (record: any) => {
  return {
    id: record.id,
    fields: record.fields,
  };
};

export function getStudent() {
  const name = 'Jenny';
  base('Students')
    .select({ filterByFormula: `{Name} = "${name}"` })
    .eachPage(
      function page(records: any, fetchNextPage: any) {
        records.forEach(function (record: any) {
          console.log('Retrieved', minifyRecord(record));
          return minifyRecord(record);
        });
        fetchNextPage();
      },
      function done(err: any) {
        if (err) {
          console.error(err);
          return;
        }
      }
    );
}
0 Replies 0