Making concurrent HTTP calls with Vue.js to fetch connected Airtable records

I have a Vue.js app that successfully fetches data from an Airtable database using HTTP requests. The basic data retrieval works fine for the main table fields. However, I’m struggling with linked records that reference other tables.

In my setup, I have a field called “COMPANY” that links to another table containing company details like “COMPANY_NAME” and “BUSINESS_TYPE”. When I try to access the nested data from the linked table, I get errors or incomplete results.

I think I need to make multiple concurrent requests to get all the data, but I’m not sure how to structure this properly. Here’s my current code:

new Vue({
  el: '#dashboard',
  data: {
    message: 'Hello from Vue',
    records: []
  },
  mounted() {
    this.fetchData();
  },
  methods: {
    fetchData() {
      const vm = this;
      const baseId = "appXYZ123ABC456";
      const apiKey = "keyABC123XYZ789";
      
      this.records = [];
      
      axios.get(
        `https://api.airtable.com/v0/${baseId}/PROJECTS?api_key=${apiKey}`,
        {
          headers: { Authorization: `Bearer ${apiKey}` }
        }
      ).then(function(res) {
        vm.records = res.data.records;
      }).catch(function(err) {
        console.log(err);
      });
    }
  }
});

How can I modify this to properly fetch and combine data from linked tables?

Both work, but they’re still pretty manual. I’ve worked with Airtable integrations for years - the real pain isn’t fetching data once.

It’s keeping everything synced, handling rate limits, and managing API calls when you scale. You end up writing tons of boilerplate just for retries and error handling.

I automate the whole pipeline instead. Set up workflows that pull from Airtable, transform linked records into exactly what your Vue app needs, then push everything to one endpoint. Your frontend makes one clean API call.

Automation handles concurrent requests behind the scenes. It caches combined data and refreshes on schedule or when Airtable records change.

Way cleaner than managing Promise.all() chains or remembering expand parameters every time. Plus you can add validation, formatting, and combine other data sources without touching Vue code.

Latenode makes this super easy - just drag and drop your Airtable connections and transformations.

The Problem:

You’re fetching data from Airtable, and you’re having trouble retrieving data from linked records in your Vue.js application. Your current code successfully fetches data from the main table, but when trying to access nested data from linked tables (specifically, the “COMPANY” field linked to a table with “COMPANY_NAME” and “BUSINESS_TYPE”), you encounter errors or incomplete results. You suspect you need to make multiple concurrent requests to gather all necessary data but are uncertain about the proper implementation.

:gear: Step-by-Step Guide:

Step 1: Utilize the expand Parameter in Your Airtable API Request.

The most efficient solution is to leverage Airtable’s expand parameter within your API request. This parameter instructs Airtable to include the linked record data directly in the response, eliminating the need for separate requests. Modify your fetchData method as follows:

fetchData() {
  const vm = this;
  const baseId = "appXYZ123ABC456";
  const apiKey = "keyABC123XYZ789";

  this.records = [];

  axios.get(
    `https://api.airtable.com/v0/${baseId}/PROJECTS?api_key=${apiKey}&expand[]=COMPANY`,
    {
      headers: { Authorization: `Bearer ${apiKey}` }
    }
  )
  .then(function(res) {
    vm.records = res.data.records;
    //Now each record will have the full COMPANY data readily available.
    console.log(vm.records[0].fields.COMPANY); // Example access to the linked record data.
  })
  .catch(function(err) {
    console.log(err);
  });
}

Notice the addition of &expand[]=COMPANY to your API URL. This tells Airtable to include the complete details of the records linked via the “COMPANY” field.

Step 2: Accessing the Expanded Data in Your Vue Component.

Once you’ve fetched the data using the expand parameter, accessing the linked record information is straightforward. Each record in vm.records will now have a fields.COMPANY property containing the complete data for the linked company record. You can access the COMPANY_NAME and BUSINESS_TYPE like this:

<template>
  <div v-for="record in records" :key="record.id">
    <h3>Project: {{ record.fields.ProjectName }}</h3>
    <p>Company: {{ record.fields.COMPANY.fields.COMPANY_NAME }}</p>
    <p>Business Type: {{ record.fields.COMPANY.fields.BUSINESS_TYPE }}</p>
  </div>
</template>

Remember to replace "ProjectName" with the actual name of your project name field in Airtable.

Step 3: Handle Potential Errors.

Always include comprehensive error handling. The .catch block in the provided code snippet provides a basic level of error handling. For production applications, you might want to implement more sophisticated error handling, such as displaying user-friendly error messages, logging errors to a central system, or implementing retry logic for transient network issues.

:mag: Common Pitfalls & What to Check Next:

  • Multiple Linked Fields: If you have multiple linked fields, simply add more expand parameters to your URL, separated by ampersands: &expand[]=COMPANY&expand[]=OTHER_LINKED_FIELD.
  • API Key and Permissions: Verify that your Airtable API key is valid and has the necessary permissions to access both the main table and the linked tables.
  • Airtable Data Integrity: Ensure that the “COMPANY” field in your “PROJECTS” table actually contains valid links to records in your company table. Incorrect or missing links will result in missing data.
  • Rate Limiting: Be mindful of Airtable’s API rate limits, especially if you’re fetching a large dataset. If you exceed the limits, you might need to implement pagination or batch requests.

:speech_balloon: Still running into issues? Share your (sanitized) config files, the exact command you ran, and any other relevant details. The community is here to help!

first thing - check your airtable api limits. you’re probably hitting rate limits with those concurrent calls. add some delays between requests or set up a queue system. also, double-check how you’re handling linked records since airtable always returns them as arrays, even when there’s just one link.

Had the same issue with a Vue.js app. Use Promise.all() to handle multiple API requests efficiently. First, fetch your main table records. Then map through them to grab the unique IDs from the COMPANY field. Make a batch request for the linked data using async/await with Promise.all() - this ensures everything loads before your app tries to render it. Just remember Airtable returns linked records as arrays, so you’ll need to handle that when combining the data.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.