⚠️ This lesson is retired and might contain outdated information.

Make a Post Request to the Airtable API with a Handler Function

Obinna Ekwuno
InstructorObinna Ekwuno
Share this video with your friends

Social Share Links

Send Tweet
Published 3 years ago
Updated 2 years ago

Create a function that handles POST requests to your API. You will also learn how to create an authenticated request using your Airtable API key.

Instructor: [0:01] If we head over to the index.js file, we can create a function that would handle our Airtable request. We can name this function handleAirtableData().

[0:16] This function would take in a body that you would post to our Airtable. We want a FETCH request that points to our Airtable API, and posts the body parameter, which is a key-value pair on the fields. We would define this [inaudible] function, but now we want to connect our function to our Airtable.

[0:45] We can do this using the parameters that we've previously stored in our environment variables, and also using this URL, as it contains the base ID and the Airtable table name. It also uses the API key for authentication. We would have to pass in an object into our FETCH function, so as to pass in the authentication required.

[1:10] If we paste in the link, we will have to change the API base ID to our environment variable that's already been defined in our angular.toml file. The first thing we want to change is the Airtable base ID, and because our table name is this string, we'll have to include the URL component into the URL as Airtable table name. Then, we can pass in the authentication requirements as an object.

[1:50] The first thing we want to define is the method that would be acted on this URL. We want it to be a POST method, because we're sending in data from a form into Airtable. Then, we just want to stringify the body using JSON.stringify. Now, we have to pass in a header, and add your authorization and the content type.

[2:14] The authorization would be our Airtable API key. This would be in the Bearer, and then followed by the API key. Since we've created this API key to be secret, we would not show in our angular.toml file, but we can still use it because we have put it into our Worker already. Then, we just want to return the content type of which the body would be displayed in.

egghead
egghead
~ 7 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today