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.
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);
In above code,
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.
That's it for this lesson, Stay connected for more learning lessons. Feel free to contact me for Airtable consulting service by Clicking Here.