-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
Copy pathcreate-table.mjs
58 lines (55 loc) · 1.52 KB
/
create-table.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import airtable from "../../airtable_oauth.app.mjs";
export default {
key: "airtable_oauth-create-table",
name: "Create Table",
description: "Create a new table. [See the documentation](https://airtable.com/developers/web/api/create-table)",
version: "0.0.11",
type: "action",
props: {
airtable,
baseId: {
propDefinition: [
airtable,
"baseId",
],
},
name: {
type: "string",
label: "Name",
description: "The name of the table",
},
description: {
type: "string",
label: "Description",
description: "The description of the table",
optional: true,
},
fields: {
type: "string[]",
label: "Fields",
description: "A list of JSON objects representing the fields in the table. [See the documentation](https://airtable.com/developers/web/api/model/field-type) for supported field types, the write format for field options, and other specifics for certain field types.",
},
},
async run({ $ }) {
const fields = [];
for (const field of this.fields) {
const fieldObj = typeof field === "object"
? field
: JSON.parse(field);
fields.push(fieldObj);
}
const response = await this.airtable.createTable({
baseId: this.baseId,
data: {
name: this.name,
description: this.description,
fields,
},
$,
});
if (response) {
$.export("$summary", `Successfully created table with ID ${response.id}.`);
}
return response;
},
};