How to send data to API from the Airtable script

Welcome to the next part of the previous lesson. In this lesson, you will learn How to send data to API from the Airtable script. This is important because when you are working with APIs, you will be sending and receiving data. You already learned how to receive data. Now let's learn how to send the data to an API. To implement the code of this lesson, I am using an online free API testing service. You can use any API once you learn the concept. Copy and paste the below code into your scripting app. Here in the below code, I am using 'https://www.appsloveworld.com/free-online-sample-rest-api-url-for-testing/' as an API to send data to.

: Code :


let dataObject = {
'tourist_name': 'Person Name',
'tourist_email': 'email@example.com',
'tourist_location': 'Location'
};
let url = 'http://restapi.adequateshop.com/api/Tourist';
let response = await remoteFetchAsync(url, {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(dataObject),
method: 'POST'
});
console.log(response);

Understanding the code:

In above code,

  1. From line no 1 to line no 5: It's an object or data that we are willing to post or create new create with
  2. On line no 6: I am storing API endpoint.
  3. From line no 7 to line no 14: I am sending a request to API with Post method to create new data.
  4. On line no 15: And Finally printing the response

This is almost the same as the previous one, except we are passing the data and using the POST method. Also, we have headers. You might need to add an authorization bearer token into the header. But for this example, you don't need any token to be sent. This code is creating data but you can use a different method like PUT to update data. The below screenshot is an example of the response that you might get with the current code.

airtable scripting app fetch data in airtable api fetch data in airtable script fetching daa in airtable script how to send data to api from the airtable script send data from airtable send data to api from airtable

That's it for this lesson, Stay connected for more learning lessons. Feel free to contact me for Airtable consulting service by Clicking Here.

monino solutions logo

COPYRIGHT © 2024 Monino Solutions.