JavaScript to sync tasks from Sflow.io to Airtable
SFlow.io is a platform for project management, ticketing system, and task workflow automation platform. People widely use Airtable as a web-based tool for organizing and storing data.You can highly customize both tools and integrate them to create a powerful solution for managing data. In this blog post, we will explain how to use the SFlow.io JavaScript engine to send tasks from SFlow.io into Airtable using the Airtable JavaScript API.
Implementation
The Airtable JavaScript API provides a set of methods for accessing and manipulating data stored in Airtable. You can use this API to perform various tasks like creating new records, updating existing records, and retrieving data.To use the Airtable JavaScript API, you will need to create an Airtable API key and pass it to the API when making requests.
To send data from SFlow.io to Airtable, you will need to use the Airtable API to create a new record in your Airtable base. You can do this by calling the create method of the Airtable API and passing in the data you want to add to Airtable. For example, the following mapping of the Airtable field to Sflow.io.
const parseAirTableFields = (issue) => {
return {
"title": issue.title,
"orderId": issue.orderId,
"description": issue.description,
"descriptionText": issue.descriptionText,
"type": issue.type,
"status": issue.status,
"priority": issue.priority,
"reporterId": issue.reporterId,
"projectId": issue.projectId,
"organizationId": issue.organizationId,
"latitude": issue.latitude,
"longitude": issue.longitude,
"dueDate": issue.dueDate,
};
}
The first step in integrating SFlow.io and Airtable is to create a table that has the field needed for Sflow.io task. Then, To do this, you will need to use the Airtable JavaScript API to create a script that read from Sflow.io task and send it to the Airtable column. This script can trigger various events in SFlow.io, such as completing a task or submitting a form.
// Entry function
const main = async () => {
switch (self.action) {
case IssueAction.create:
await createIssue();
break;
case IssueAction.update:
await updateIssue();
break;
case IssueAction.softDelete:
break;
case IssueAction.hardDelete:
await deleteIssue();
break;
case IssueAction.test:
break;
case IssueAction.call:
break;
case IssueAction.column:
break;
}
};
// Is currently in async function
return await main();
First, when issues change event, call API to do the related action.
const createIssue = async () => {
const data = {
"records": [
{
"fields": parseAirTableFields(self.issue)
}
]
};
const { err, res } = await http.send("post", baseURL,
{
headers, data, timeout
});
if (err) {
system.printf("createIssue Error", err);
return;
}
if (!(res.status == 200 && res.data.records.length > 0))
system.printf("Issue Creation Failure", res);
else {
const ticketId = res.data.records[0].id;
system.printf(`Issue Created TicketId:${ticketId}`);
await self.issue.set("airtable_id", ticketId);
}
};
const updateIssue = async () => {
const ticketId = await findTicketId();
if (ticketId == -1) return;
system.printf(ticketId);
const data = {
"records": [
{
"id": ticketId,
"fields": parseAirTableFields(self.issue)
}
]
};
const { err, res } = await http.send("patch", baseURL,
{
headers, data, timeout
});
if (err) {
system.printf("updateIssue Error", err);
return;
}
if (!(res.status == 200 && res.data.records.length > 0))
system.printf("Issue Update Failure", res);
else {
const ticketId = res.data.records[0].id;
system.printf(`Issue Update TicketId:${ticketId}`);
}
};
const deleteIssue = async () => {
const ticketId = await findTicketId();
if (ticketId == -1) return;
const { err, res } = await http.send("delete", `${baseURL}?records[]=${ticketId}`,
{
headers, timeout
});
if (err) {
system.printf("deleteIssue Error", err);
return;
}
if (!(res.status == 200 && res.data.records.length > 0))
system.printf("Issue Delete Failure", res);
else {
const ticketId = res.data.records[0].id;
system.printf(`Issue Delete TicketId:${ticketId}`);
await self.issue.del("airtable_id");
}
};
Once you have added data to Airtable, you can use the Airtable API to retrieve this data and use it within SFlow.io. For example, you could retrieve the data for a specific record in Airtable and use it to populate a task in SFlow.io if the task is not present in Sflow.io.
In addition to sending data from SFlow.io to Airtable, you can also use the Airtable JavaScript API to implement bidirectional synchronization of data between SFlow.io and Airtable. Use the Airtable API to monitor changes in Airtable. And updating data in SFlow.io in response using Sflow.io webhook.
Conclusion
In conclusion, integrating SFlow.io and Airtable provides a powerful solution for automating tasks and managing data. By using the SFlow.io JavaScript engine and the Airtable JavaScript API, you can easily send data from SFlow.io to Airtable and keep both platforms in sync. More blog about Sflow.io project management. such as Agile software development with Sflow.io, How to use process kanban to manage work. Register for free Sflow.io to get your project done faster.