Skip to content

Commit 4dfe1c3

Browse files
committed
More improvements
1 parent 6fa6f05 commit 4dfe1c3

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

components/airtable_oauth/actions/create-multiple-records/create-multiple-records.mjs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import chunk from "lodash.chunk";
22
import airtable from "../../airtable_oauth.app.mjs";
33
import common from "../common/common.mjs";
4+
import { ConfigurationError } from "@pipedream/platform";
45

56
const BATCH_SIZE = 10; // The Airtable API allows us to update up to 10 rows per request.
67

78
export default {
89
key: "airtable_oauth-create-multiple-records",
910
name: "Create Multiple Records",
10-
description: "Create one or more records in a table by passing an array of objects containing field names and values as key/value pairs. [See the documentation](https://airtable.com/developers/web/api/create-records)",
11-
version: "0.0.6",
11+
description: "Create one or more records in a table in a single operation with an array. [See the documentation](https://airtable.com/developers/web/api/create-records)",
12+
version: "0.1.{{ts}}",
1213
type: "action",
1314
props: {
1415
...common.props,
@@ -18,6 +19,15 @@ export default {
1819
"records",
1920
],
2021
},
22+
customExpressionInfo: {
23+
type: "alert",
24+
alertType: "info",
25+
content: `You can use a custom expression that evaluates to an object for each entry in the array, e.g. \`{{ { "foo": "bar", "id": 123 } }}\`.
26+
\\
27+
You can also reference an object exported by a previous step, e.g. \`{{steps.foo.$return_value}}\`.
28+
\\
29+
If desired, you can use a custom expression in the same fashion for the entire array instead of providing individual values.`,
30+
},
2131
typecast: {
2232
propDefinition: [
2333
airtable,
@@ -39,9 +49,18 @@ export default {
3949
if (!Array.isArray(data)) {
4050
data = JSON.parse(data);
4151
}
42-
data = data.map((fields) => ({
43-
fields,
44-
}));
52+
data = data.map((fields, index) => {
53+
if (typeof fields === "string") {
54+
try {
55+
fields = JSON.parse(fields);
56+
} catch (err) {
57+
throw new ConfigurationError(`Error parsing record (index ${index}) as JSON: ${err.message}`);
58+
}
59+
}
60+
return {
61+
fields,
62+
};
63+
});
4564
if (!data.length) {
4665
throw new Error("No Airtable record data passed to step. Please pass at least one record");
4766
}

components/airtable_oauth/airtable_oauth.app.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ export default {
205205
optional: true,
206206
},
207207
records: {
208-
type: "string",
208+
type: "string[]",
209209
label: "Records",
210-
description: "Provide an array of objects. Each object should represent a new record with the column name as the key and the data to insert as the corresponding value (e.g., passing `[{\"foo\":\"bar\",\"id\":123},{\"foo\":\"baz\",\"id\":456}]` will create two records and with values added to the fields `foo` and `id`). The most common pattern is to reference an array of objects exported by a previous step (e.g., `{{steps.foo.$return_value}}`). You may also enter or construct a string that will `JSON.parse()` to an array of objects.",
210+
description: "Each item in the array should be an object in JSON format, representing a new record. The keys are the column names and the corresponding values are the data to insert.",
211211
},
212212
typecast: {
213213
type: "boolean",
@@ -224,7 +224,7 @@ export default {
224224
type: "alert",
225225
alertType: "info",
226226
content: `A custom expression can be a JSON object with key/value pairs representing columns and values, e.g. \`{{ { "foo": "bar", "id": 123 } }}\`.
227-
\\\\
227+
\\
228228
You can also reference an object exported by a previous step, e.g. \`{{steps.foo.$return_value}}\`.`,
229229
},
230230
},

0 commit comments

Comments
 (0)