Converting Airtable cURL POST request to VB.NET - getting 422 error

I’m struggling with creating new records in Airtable using my VB.NET application. Reading data works perfectly, but when I try to POST new entries I keep hitting a wall with a 422 Unprocessable Entity error. I’m not sure if my JSON formatting is wrong or if I’m missing something in the request headers.

Here’s my current code:

Dim headers As New WebHeaderCollection()
headers.Clear()
headers.Add("Authorization: Bearer keyAbc123DefXXXXX")

Dim apiUrl As String = "https://api.airtable.com/v0/appXyz789AbcDef12/Records"

Dim request As HttpWebRequest = CType(HttpWebRequest.Create(apiUrl), HttpWebRequest)
request.ContentType = "application/json"
request.Headers = headers
request.Method = "POST"
request.Accept = "*/*"

Dim jsonData = "{""fields"": {""CompanyName"": ""testApp"", ""Event"": ""click"", ""Username"": ""john_doe""}}"

request.GetRequestStream.Write(Encoding.UTF8.GetBytes(jsonData), 0, Encoding.UTF8.GetBytes(jsonData).Length)

Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
Dim result As String = ""

Using reader As New StreamReader(response.GetResponseStream())
    result = reader.ReadToEnd()
End Using

MessageBox.Show(result)

Any ideas what might be causing this 422 error? I’ve double-checked my API key and base ID, so I think the issue is with how I’m structuring the POST data.

I hit this exact same issue last month switching from cURL to VB.NET for Airtable. Your JSON structure’s the problem - Airtable wants a “records” array even for single records. You’re missing that wrapper.

Change your jsonData to:

Dim jsonData = "{""records"": [{""fields"": {""CompanyName"": ""testApp"", ""Event"": ""click"", ""Username"": ""john_doe""}}]}"

Also throw a Using statement around your request stream for proper disposal. Your auth and content-type headers look fine - I used the same setup. That 422 error means the API got your request but couldn’t process it, which with Airtable usually comes down to missing the records array.