0

Delete Record

by
Published Jun 6, 2022
Script airtable Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 14 days ago
1
//native
2

3
type Airtable = {
4
  apiKey: string;
5
};
6

7
type AirtableTable = {
8
  baseId: string;
9
  tableName: string;
10
};
11
export async function main(
12
  atCon: Airtable,
13
  atTable: AirtableTable,
14
  recordId: string,
15
) {
16
  const url = `https://api.airtable.com/v0/${atTable.baseId}/${encodeURIComponent(
17
    atTable.tableName,
18
  )}/${recordId}`;
19

20
  const response = await fetch(url, {
21
    method: "DELETE",
22
    headers: {
23
      Authorization: `Bearer ${atCon.apiKey}`,
24
      "Content-Type": "application/x-www-form-urlencoded",
25
    },
26
  });
27

28
  if (!response.ok) {
29
    throw new Error(`${response.status} ${await response.text()}`);
30
  }
31

32
  const deleteSingleRecord = await response.json();
33

34
  return deleteSingleRecord;
35
}
36

Other submissions
  • Submitted by hugo697 Deno
    Created 406 days ago
    1
    import { Airtable } from "https://deno.land/x/airtable/mod.ts";
    2
    
    
    3
    type Airtable = {
    4
      apiKey: string;
    5
    };
    6
    
    
    7
    type AirtableTable = {
    8
      baseId: string;
    9
      tableName: string;
    10
    };
    11
    export async function main(
    12
      atCon: Airtable,
    13
      atTable: AirtableTable,
    14
      recordId: string,
    15
    ) {
    16
      const airtable = new Airtable({ ...atCon, ...atTable });
    17
    
    
    18
      const deleteSingleRecord = await airtable.delete(recordId);
    19
    
    
    20
      return deleteSingleRecord;
    21
    }
  • Submitted by rossmccrann Deno
    Created 1039 days ago
    1
    import { Airtable } from "https://deno.land/x/airtable/mod.ts";
    2
    import { Field } from "https://deno.land/x/airtable/mod.ts";
    3
    
    
    4
    type Airtable = {
    5
      apiKey: string;
    6
    };
    7
    
    
    8
    type AirtableTable = {
    9
      baseId: string;
    10
      tableName: string;
    11
    };
    12
    export async function main(
    13
      at_con: Airtable,
    14
      at_table: AirtableTable,
    15
      recordId: string,
    16
    ) {
    17
      const airtable = new Airtable({ ...at_con, ...at_table });
    18
    
    
    19
      const deleteSingleRecord = await airtable.delete(recordId);
    20
    
    
    21
      return { message: "Deleted single record in table" };
    22
    }
    23