![Tiago_Formosinh Tiago_Formosinh](https://community.airtable.com/legacyfs/online/avatars/3X/d/a/da72413ba303437658721dd105d66daff210eac1.png)
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sep 26, 2019 03:24 AM
So this is what I am using to get my data from airtable
import axios from "axios"
formSubmitHandler = e => {
axios
.get(
"https://api.airtable.com/v0/" + app_id + "/" + view,
{ headers: { Authorization: "Bearer " + app_key } },
)
.then(resp => console.log(resp))
.catch(error => console.log(error))
e.preventDefault()
}
This works very well, however when I try to post something into the same table and now using this:
formSubmitHandler = e => {
const { name, email } = this.state
const data = {
"records": [
{
"fields": {
"Name": name,
"Email": email,
}
}
]
}
console.log(data)
axios
.post(
"https://api.airtable.com/v0/" + app_id + "/" + view,
{ headers: { Authorization: "Bearer " + app_key } },
data
)
.then(resp => console.log(resp))
.catch(error => console.log(error))
e.preventDefault()
}
It doesn’t work and I always get ERROR 401, and that shouldn’t be the case as I already managed to get the information out of my airtable.
Any ideas why this is happening?
Thank you,
Tiago
Solved! Go to Solution.
![Bill_French Bill_French](https://community.airtable.com/legacyfs/online/avatars/3X/f/f/ffbb19c12cc40abf5dcf843b92eec175af975d64.png)
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sep 26, 2019 07:51 AM
That looks okay but you might try using a table name instead of a view name. I say this only because I’m unsure about Axios requirements - best to eliminate this as a potential cause.
Since you’re getting a 401 are you absolutely sure that the API key of the user with access to the base granted read and write authority? This is unlikely to be the issue, but I always like to ask the obvious because that would cause the behavior you are experiencing - read/GET works, write/POST fails.
![Tiago_Formosinh Tiago_Formosinh](https://community.airtable.com/legacyfs/online/avatars/3X/d/a/da72413ba303437658721dd105d66daff210eac1.png)
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sep 26, 2019 07:56 AM
Thank you! I think the order was the thing that was wrong!
const data = {
"records": [
{
"fields": {
"Name": name,
"Email": email,
}
}
]
}
let url = "https://api.airtable.com/v0/" + app_id + "/" + view
let axiosConfig = { headers: { Authorization: "Bearer " + app_key , 'Content-Type': 'application/json' } }
axios
.post(
url,
data,
axiosConfig
)
.then(resp => console.log(resp))
.catch(error => console.log(error))
Like this works!
Thank you so much for the help!
Really appreciate!
![snow_jhon snow_jhon](https://community.airtable.com/legacyfs/online/avatars/2X/3/3df142637b7e85d6283b8fe84279236e14a5df85.png)
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sep 30, 2019 07:30 AM
Since you’re getting a 401 are you absolutely sure that the API key of the user with access to the base granted read and write authority? This is unlikely to be the issue, but I always like to ask the obvious because that would cause the behavior you are experiencing - read/GET works, write/POST fails.
![Tiago_Formosinh Tiago_Formosinh](https://community.airtable.com/legacyfs/online/avatars/3X/d/a/da72413ba303437658721dd105d66daff210eac1.png)
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sep 30, 2019 09:33 AM
@snow_jhon, nope the issue was that my axiosConfig
was incomplete. ‘Content-Type’: ‘application/json’ needs to be there.
![Tiago_Formosinh Tiago_Formosinh](https://community.airtable.com/legacyfs/online/avatars/3X/d/a/da72413ba303437658721dd105d66daff210eac1.png)
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oct 06, 2019 06:51 AM
By the way, the reason I was trying to implement this was because I wanted to put a contact from in my blog. I actually wrote about it on this post https://tiagofsanchez.netlify.com/2019-10-06-blog-series-building-a-contact-form-with-airtable/
it anyone is keen to have a read.
Again, thank you for the help.
![Boston_Jones Boston_Jones](https://community.airtable.com/legacyfs/online/avatars/2X/6/624bac23ccaf551683ab4d6c94c44169eff2ad46.png)
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oct 10, 2019 07:26 AM
As a developer you get to create a database with a very nice to use interface.
![Michael_Preston Michael_Preston](https://community.airtable.com/legacyfs/online/avatars/2X/d/d2cddef9eb97d3a7e3d71490df054b61bc561aec.png)
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Feb 16, 2022 12:26 AM
I can confirm this was the exact problem and solution I had as well.
I think my issue was not wrapping the headers inside a property like you did:
let axiosConfig = { headers: { Authorization: "Bearer " + app_key , 'Content-Type': 'application/json' } }
Mine was:
const headers = {
'Authorization': `Bearer <apiKey>`,
'Content-Type': 'application/json',
'Accept': 'application/json',
};
axios.post(url, data, headers).then((result) => {
Log(result)
let raw = formatRecords(result?.data?.records);
state.value.record = raw;
Log("state.value.records", state.value.records);
}).catch(error => {
loading.value = false;
error.value = error;
})
This makes sense, if axios was looking for a “headers” prop, but found no such prop.
![](/skins/images/DD0CD7D0ACF200EF4456420D87029A3D/responsive_peak/images/icon_anonymous_message.png)
- « Previous
-
- 1
- 2
- Next »