I’m working on a web application where I need to send form data to Airtable using their API. I keep getting an error message about missing fields in the request body. The error says: {"error":{"type":"INVALID_REQUEST_MISSING_FIELDS","message":"Could not find field \"fields\" in the request body"}}. I’m pretty new to working with APIs and JavaScript, so I might be making a basic mistake. Here’s the code I’m using:
var contactForm = document.querySelector("#contact-form");
if(contactForm) {
contactForm.addEventListener("submit", function(e) {
e.preventDefault();
axios.post(airtable_api_url,
{
"Content-Type": "application/json"
},
{
"fields": {
"FullName": document.getElementById("full-name").value,
"EmailAddress": document.getElementById("email").value,
"PhoneNumber": document.getElementById("phone").value,
"Subject": document.getElementById("subject").value,
"Message": document.getElementById("message").value,
"Source": "Website"
}
})
.then(function(res) {
console.log(res);
})
.catch(function(err) {
console.log(err);
})
})
};
Can someone help me figure out what’s wrong with my request structure?