-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Expand file tree
/
Copy pathcreate-record.mjs
More file actions
71 lines (66 loc) · 1.64 KB
/
create-record.mjs
File metadata and controls
71 lines (66 loc) · 1.64 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
import caspio from "../../caspio.app.mjs";
import { ConfigurationError } from "@pipedream/platform";
export default {
key: "caspio-create-record",
name: "Create Record",
description: "Create a new record in the specified table. [See the documentation](https://demo.caspio.com/integrations/rest/swagger/index.html)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: false,
},
props: {
caspio,
table: {
propDefinition: [
caspio,
"table",
],
reloadProps: true,
},
},
async additionalProps() {
const props = {};
const { Result: fields } = await this.caspio.listTableFields({
table: this.table,
});
for (const field of fields) {
if (!field.Editable) continue;
props[field.Name] = {
type: field.Type === "YES/NO"
? "boolean"
: "string",
label: field.Name,
optional: true,
};
}
return props;
},
async run({ $ }) {
const {
caspio,
table,
...data
} = this;
if (Object.keys(data).length === 0) {
throw new ConfigurationError("Must provide at least one field");
}
const { Result: fields } = await this.caspio.listTableFields({
table: this.table,
});
for (const field of fields) {
if (field.Type === "NUMBER" && data[field.Name]) {
data[field.Name] = +data[field.Name];
}
}
const response = await caspio.createRecord({
$,
table,
data,
});
$.export("$summary", `Successfully created record in table ${table}`);
return response;
},
};