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.