Help

Save the date! Join us on October 16 for our Product Ops launch event. Register here.

Re: POST https://api.airtable.com 422 (Unprocessable Entity)

3737 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Chris_Grim
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi All, I am having an issue with creating new entries into my airtable. I am able to GET the data from my airtable with the axios code:
getTable() {
axios.defaults.headers = {
Authorization: ‘Bearer key$$$$$#@@@@’
}
axios.get(‘api.airtablenolinksallowed/v0/applHDrandomTWT/tasks’)
.then(response => {
console.log(response);
})
},

However, when I try to post to the same table I am getting the error: POST api.airtablenolinksallowed/v0/applxDrxrandomzTWT/tasks 422 (Unprocessable Entity)

Here is my axios for post:
postTable() {
axios.defaults.headers = {
‘Content-Type’: ‘application/json’,
Authorization: ‘Bearer key$$####$$$#’
}
let data = {};
data.Name = ‘TestName’;
data.Notes = ‘ASXXZSXSZX’
console.log(data);
axios.post(‘api.airtablenolinksallowed/v0/applHDrrandomTWT/tasks’, data)
.then(response => {
console.log(response);
})
},

What am I doing wrong with my axios post?

4 Replies 4
Chris_Grim
5 - Automation Enthusiast
5 - Automation Enthusiast

I figured it out! I wasn’t passing the correct array.
I switched to
let Name = {Name:‘name’};
let Notes = {Notes:‘MoreNotes’};
let data = {
fields: {
Name:‘name’,
Notes:‘MoreNotes’
}};
And it worked!

Mxolisi_Ngwenya
4 - Data Explorer
4 - Data Explorer

Hi,

I am having the same problem but I’m coding in python, I am having a difficulty in applying the solution you posted above and I understand it might be a programming language issue.

Here is the code I have:

_airtable = airtable.Airtable(‘XXXXXX’, ‘XXXXXX’)

print(_airtable.get(“Test”)) #get data from table
try:
data = {
‘Name’: ‘Mxolisi’,
‘Notes’: ‘This Python Will swallow you’,
‘Attachment’: ‘1_U2MpZQXPI-RW2JASIoeaFQ.png’
}
_create = _airtable.create(‘Test’, data)
print(_create)
except Exception as e:
print("Exception Caught : ", e)
finally:
print(“Done!!”)

Chris_Grim
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi @Mxolisi_Ngwenya
I am still a new beginner at this but I believe your issue might be similar to mine. You currently have

data = { ‘Name’: ‘Mxolisi’, }

but I believe what you need is

data = { fields: { ‘Name’: ‘Mxolisi’ }}

Let me know if that works!

As per @Chris_Grim, the data object has to have a fields object within it, e.g.:

data = {
    "fields": {
        "Field1": name,
        "Field2": number,
        "Field3": role
        }
    } 

Additionally, if you are trying to add an attachment to a record via the API note that it accepts an array of objects (even if there is only one attachment), so you data object might be something like:

"fields": {
    "Attachment": [
      {
        "url": "https://mysite.com/images/myimage.png"
      }
    ]
  }

JB