Skip to content

ListRecords

ngocnicholas edited this page Mar 30, 2017 · 1 revision

AirtableBase.ListRecords Method(string, string, IEnumerable, string, int?, int?, IEnumerable, string)

Get a list of records in a specific table. Start the listing at a specific offset. Specify what fields should be included in the record together with a specific filter formula, the number of records per page. Specify how the record list should be sorted and from which view of the table. This method is an asynchronous operation.

Namespace: AirtableApiClient

Assembly: AirtableApiClient.dll

Syntax

        public async Task<AirtableListRecordsResponse> ListRecords(
            string tableName,
            string offset = null,
            IEnumerable<string> fields = null,
            string filterByFormula = null,
            int? maxRecords = null,
            int? pageSize = null,
            IEnumerable<Sort> sort = null,
            string view = null)

Parameters

tableName

Type: string   
Name of the table of which the records to be retrieved from

offset

Type: string
offset into the table where the record listing starts

fields

Type: Fields

filterByFormula

Type: string

maxRecords

Type: int

pageSize

Type int

sort

Type: Sort

view

Type: string

Return Value

The task object representing the asynchronous operation.

Remarks

This operation will not block. The returned task object will complete once the entire response including content is read.

Example

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AirtableApiClient;
        readonly string baseId = YOUR_BASE_ID;
        readonly string appKey = YOUR_APP_KEY;  

        string offset = null;
        string errorMessage = null;
        var records = new List<AirtableRecord>();

        try
        {
           using (AirtableBase airtableBase = new AirtableBase(appKey, baseId))
           {
               //
               // Only use a 'do while' loop if you want to get multiple pages
               // of records.
               //

               do
               {
                   Task<AirtableListRecordsResponse> task = airtableBase.ListRecords(
                       YOUR_TABLE_NAME, 
                       offset, 
                       fieldsArray, 
                       filterByFormula, 
                       maxRecords, 
                       pageSize, 
                       sort, 
                       view);

                    AirtableListRecordsResponse response = await task;

                    if (response.Success)
                    {
                        records.AddRange(response.Records.ToList());
                        offset = response.Offset;
                    }
                    else if (response.AirtableApiError is AirtableApiException)
                    {
                        errorMessage = response.AirtableApiError.ErrorMessage;
                        break;
                    }
                    else
                    {
                        errorMessage = "Unknown error";
                        break;
                    }
                } while (offset != null);
            }
        }

        catch (Exception e)
        {
            errorMessage = e.Message;
        }

        if (!string.IsNullOrEmpty(errorMessage))
        {
            // Error reporting
        }
        else
        {
            // Do something with the retrieved 'records' and the 'offset'
            // for the next page of the record list.
        } 
    }

Clone this wiki locally