Trouble adding records to Airtable using .NET: How to fix 422 error?

I’m stuck trying to add a new record to my Airtable database using a .NET app. Reading data works fine, but when I try to POST, I keep getting a ‘422 Unprocessable Entity’ error. I’m not sure if I’m formatting the data wrong or if there’s an issue with my headers.

Here’s a simplified version of what I’m trying:

var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer mySecretKeyHere");

var data = new
{
    fields = new
    {
        ProjectName = "Demo",
        Status = "In Progress",
        Owner = "John Doe"
    }
};

var json = JsonConvert.SerializeObject(data);
var content = new StringContent(json, Encoding.UTF8, "application/json");

var response = await client.PostAsync("https://api.airtable.com/v0/myBaseId/myTableName", content);

if (!response.IsSuccessStatusCode)
{
    Console.WriteLine($"Error: {response.StatusCode}");
}

Any ideas on what I might be doing wrong? I’ve double-checked my API key and base ID, but I’m still stumped. Help would be much appreciated!

I’ve encountered this issue before, and it can be frustrating. One thing that helped me was double-checking the data types of each field. Airtable can be quite strict about this. For example, if ‘Status’ is a single select field in your Airtable, make sure the value you’re sending matches one of the predefined options exactly.

Another potential gotcha is linked records. If any of your fields are linked to another table, you need to send the record ID instead of the display value. This tripped me up for a while.

Lastly, I’d recommend using Postman or a similar tool to test your API calls before implementing them in code. It can help isolate whether the issue is with your data or your C# implementation. Hope this helps you troubleshoot!

hey mate, i had a similar issue. make sure ur field names in the json match EXACTLY with ur airtable column names. also, check if any required fields are missing. sometimes airtable’s picky bout data types too. if that don’t work, try using airtable’s official .NET SDK instead of raw HTTP requests. good luck!

Based on my experience, a 422 error often means the payload isn’t formatted exactly as Airtable expects. I found that ensuring the field names are exactly the same as in the Airtable base is crucial, including matching the case. It is also important to include every required field and verify that each value uses the appropriate data type. In one instance, switching to Airtable’s .NET SDK simplified things, as it managed some of these details automatically. Logging the full error response might reveal more specific issues.