From 7bca3d9c15972de1c97199cfb5b0f9f42bfc6912 Mon Sep 17 00:00:00 2001 From: dhselar1423 Date: Mon, 23 Oct 2023 16:57:52 +0530 Subject: [PATCH] made suggested changes --- docs/integrations/apis/airtable-tasks.mdx | 97 ++++++++++++++++++++--- docs/integrations/apis/airtable.mdx | 4 +- 2 files changed, 87 insertions(+), 14 deletions(-) diff --git a/docs/integrations/apis/airtable-tasks.mdx b/docs/integrations/apis/airtable-tasks.mdx index 14199b65a..184ca7e49 100644 --- a/docs/integrations/apis/airtable-tasks.mdx +++ b/docs/integrations/apis/airtable-tasks.mdx @@ -14,8 +14,9 @@ Tasks are executed after the job is triggered and are the main building blocks o Gets multiple records for a table. You can filter. [Official Airtable Docs](https://airtable.com/developers/web/api/update-multiple-records) ```ts example.ts - //gets multiple records from the table. Here we only get the Status fields (columns) - const records = await table.getRecords("muliple records", { fields: ["Status"] }); +//gets multiple records from the table. +// Here we only get the Status fields (columns) + await table.getRecords("muliple records", { fields: ["Status"] }); ``` @@ -25,7 +26,7 @@ Gets a single record (using the id) for a table. [Official Airtable Docs](https: ```ts example.ts // Get a single record using the ID of the first record in the fetched records. -const aRecord = await table.getRecord("single", records[0].id); +await table.getRecord("single", records[0].id); ``` @@ -35,10 +36,12 @@ Create one or more records in a table.[Official Airtable Docs](https://airtable. ```ts example.ts // Create newRecords by adding a record to the table. -const newRecords = await table.createRecords("create records", [ +await table.createRecords("create records", [ { - // Define the new record to be created with field values for "Launch goals" and "Status." - fields: { "Launch goals": "Created from Trigger.dev", Status: "In progress" }, + // Define the new record to be created + // with field values for "Launch goals" and "Status." + fields: { "Launch goals": "Created from Trigger.dev", + Status: "In progress" }, }, ]); ``` @@ -50,12 +53,13 @@ Update one or more records in a table.[Official Airtable Docs](https://airtable. ```ts example.ts // Update the record that was just created. -const updatedRecords = await table.updateRecords( - // Specify the table's name as "update records." +await table.updateRecords( +// Specify the table's name as "update records." "update records", - // Use the `map` method to create an array of records to be updated. +// Use the `map` method to create an array of records to be updated. newRecords.map((record) => ({ - // For each record, specify the ID and the field to update ("Status" to "At risk"). +/*For each record, specify the : +ID and the field to update ("Status" to "At risk").*/ id: record.id, fields: { Status: "At risk" }, })) @@ -69,7 +73,7 @@ Delete one or more records in a table (using ids).[Official Airtable Docs](https ```ts example.ts // Delete records from the table. -const deletedRecords = await table.deleteRecords( +await table.deleteRecords( // Specify the table's name as "delete records." "delete records", ); @@ -80,4 +84,75 @@ const deletedRecords = await table.deleteRecords( Do anything that’s possible with the official Airtable Node SDK. +## Usage + +Include the Airtable integration in your Trigger.dev job. + +You can optionally add the types for your Table – this gives you nice type inference and errors when writing your code. + +```ts +//this is the type definition for my Table +type LaunchGoalsAndOkRs = { + "Launch goals"?: string; + DRI?: Collaborator; + Team?: string; + Status?: "On track" | "In progress" | "At risk"; + "Key results"?: Array; + "Features (from 💻 Features table)"?: Array; + "Status (from 💻 Features)": Array< + "Live" | "Complete" | "In progress" | "Planning" | "In reviews" + >; +}; + +client.defineJob({ + id: "airtable-example-1", + name: "Airtable Example 1: getRecords", + version: "0.1.0", + trigger: eventTrigger({ + name: "airtable.example", + }), + integrations: { + //make sure to add the integration here + airtable, + }, + run: async (payload, io, ctx) => { + //adding the type to table("") gives you nice type inference and errors + //you can leave it out as well table("") + const table = io.airtable.base("").table(""); + + //gets multiple records from the table. Here we only get the Status fields (columns) + const records = await table.getRecords("muliple records", { fields: ["Status"] }); + await io.logger.log(records[0].fields.Status ?? "no status"); + + //Get a single record + const aRecord = await table.getRecord("single", records[0].id); + + //create a new record + const newRecords = await table.createRecords("create records", [ + { + fields: { "Launch goals": "Created from Trigger.dev", Status: "In progress" }, + }, + ]); + + //update the record we just created + const updatedRecords = await table.updateRecords( + "update records", + newRecords.map((record) => ({ + id: record.id, + fields: { Status: "At risk" }, + })) + ); + + //wait 5 seconds + await io.wait("5 secs", 5); + + //delete the record we just created + updated + const deletedRecords = await table.deleteRecords( + "delete records", + updatedRecords.map((record) => record.id) + ); + }, +}); +``` + diff --git a/docs/integrations/apis/airtable.mdx b/docs/integrations/apis/airtable.mdx index 690186935..3e913c913 100644 --- a/docs/integrations/apis/airtable.mdx +++ b/docs/integrations/apis/airtable.mdx @@ -5,9 +5,7 @@ sidebarTitle: Overview & authentication ## Overview -Our Airtable integration provides a versatile way to enhance data management, collaboration, and workflow automation. - - You can customize triggers and tasks to fit your unique use cases and business processes, helping your team become more efficient and productive. +Our Airtable integration allows you to easily connect to the Airtable API and perform tasks such as creating/updating/deleting single or multiple records in your tables. For examples of some of the things you can do with it, check out our Jobs Showcase: