Last active
June 5, 2021 05:48
-
-
Save Gbaja/b05290b58066078d2980eef1f87f8dbb to your computer and use it in GitHub Desktop.
Example of how to retrieve and delete using the airtable api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The information of the person you want to add | |
// Please note that they key has to match the wait the field is defined in your spreadsheet. | |
// The person table is linked to the Countries table. A person can have more than one country so you pass an array of all the countries Ids that the user belongs to. | |
const newPersonInfo = { | |
"First name": "Fatimat", | |
"Last Name": "Badmus", | |
Countries: ["recWWTmP55RDo2Abu"] | |
}; | |
const createRecord = () => | |
fetch("https://api.airtable.com/v0/appeu986STff75kfh/People?api_key=YOUR-API-KEY", | |
{ method: "POST", | |
body: JSON.stringify({ fields: newPersonInfo }), | |
headers: { "Content-Type": "application/json" } | |
} | |
) | |
.then(response => response.json()) | |
.then(submitConformation => console.log("SUBMITED: ", submitConformation)) | |
// Retrieves all the people(rows) in my people sheet | |
const getPeopleRecords = () => | |
fetch("https://api.airtable.com/v0/appeu986STff75kfh/People?api_key=YOUR-API-KEY") | |
.then(response => response.json()) | |
.then(records => console.log("RECORDS: ", records)); | |
// Deletes a record(row) with the id from the people sheet | |
const deleteRecord = id => | |
fetch(`https://api.airtable.com/v0/appeu986STff75kfh/People/${id}?api_key=YOUR-API-KEY`, { method: "DELETE" }) | |
.then(response => response.json()) | |
.then(deleteConfirmation => console.log("DELETE: ", deleteConfirmation)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment