How to send multiple entries to Airtable via C# REST API calls

Need help with batch inserting data to Airtable

I’m working on a project where I can successfully add one record to my Airtable base, but I can’t figure out how to add multiple records at once.

Here’s my working code for single record creation:

public static async Task CreateSingleEntry()
{
    using (var client = new HttpClient())
    {
        using (var req = new HttpRequestMessage(new HttpMethod("POST"), "https://api.airtable.com/v0/BASE_ID/TableName"))
        {
            req.Headers.TryAddWithoutValidation("Authorization", "Bearer YOUR_TOKEN");
            req.Content = new StringContent("{\"records\": [{  \"fields\": {    \"Name\": \"Sample Entry\"  }}]}");
            req.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
            var result = await client.SendAsync(req);
        }
    }
}

I’ve created these classes for handling the data structure:

using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace MyProject
{
    public class AirtableModel
    {
        public class ItemFields
        {
            [JsonPropertyName("Name")]
            [JsonInclude]
            public string Name { get; set; }
        }

        public class DataRecord
        {
            [JsonPropertyName("fields")]
            [JsonInclude]
            public ItemFields fields { get; set; }
        }

        public class RequestBody
        {
            [JsonPropertyName("records")]
            [JsonInclude]
            public List<DataRecord> records { get; set; }
        }
    }
}

The expected JSON format should look like this:

{
  "records": [
    {
      "id": "rec123ABC",
      "fields": {
        "Name": "First Item"
      }
    },
    {
      "id": "rec456DEF", 
      "fields": {
        "Name": "Second Item"
      }
    }
  ]
}

How can I populate my model from a data source like a list or grid and serialize it properly for the API request? Any guidance would be appreciated.

Your structure’s actually correct for batch operations. You just need to populate the RequestBody class with multiple DataRecord objects and serialize it.

Here’s how I handle batch inserts:

public static async Task CreateMultipleEntries(List<string> names)
{
    var requestBody = new AirtableModel.RequestBody
    {
        records = names.Select(name => new AirtableModel.DataRecord
        {
            fields = new AirtableModel.ItemFields { Name = name }
        }).ToList()
    };

    var jsonContent = JsonSerializer.Serialize(requestBody);

    using (var client = new HttpClient())
    {
        using (var req = new HttpRequestMessage(HttpMethod.Post, "https://api.airtable.com/v0/BASE_ID/TableName"))
        {
            req.Headers.TryAddWithoutValidation("Authorization", "Bearer YOUR_TOKEN");
            req.Content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
            var result = await client.SendAsync(req);
        }
    }
}

Airtable limits batch operations to 10 records per request, so chunk larger datasets. The id field in your JSON example is only for updates, not creating new records.