Skip to content

Commit 100ba05

Browse files
committed
Added actions
1 parent ada410b commit 100ba05

File tree

4 files changed

+165
-16
lines changed

4 files changed

+165
-16
lines changed

components/plecto/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import app from "../../plecto.app.mjs";
2+
3+
export default {
4+
key: "plecto-create-registration",
5+
name: "Create Registration",
6+
description: "Creates a new registration in Plecto. [See the documentation](https://docs.plecto.com/kb/guide/en/overview-of-plecto-api-endpoints-Qvm3c3ucy1/Steps/3879885,3896454)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
dataSource: {
12+
propDefinition: [
13+
app,
14+
"dataSource",
15+
],
16+
},
17+
member: {
18+
propDefinition: [
19+
app,
20+
"member",
21+
],
22+
},
23+
externalId: {
24+
propDefinition: [
25+
app,
26+
"externalId",
27+
],
28+
},
29+
date: {
30+
propDefinition: [
31+
app,
32+
"date",
33+
],
34+
},
35+
productName: {
36+
propDefinition: [
37+
app,
38+
"productName",
39+
],
40+
},
41+
unitsSold: {
42+
propDefinition: [
43+
app,
44+
"unitsSold",
45+
],
46+
},
47+
},
48+
async run({ $ }) {
49+
const response = await this.app.createRegistration({
50+
$,
51+
data: {
52+
"data_source": this.dataSource,
53+
"member": this.member,
54+
"external_id": this.externalId,
55+
"date": this.date,
56+
"Product Name": this.productName,
57+
"Units Sold": this.unitsSold,
58+
},
59+
});
60+
$.export("$summary", "Successfully created registration with ID: " + response.id);
61+
return response;
62+
},
63+
};

components/plecto/app/plecto.app.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

components/plecto/plecto.app.mjs

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import { axios } from "@pipedream/platform";
2+
3+
export default {
4+
type: "app",
5+
app: "plecto",
6+
propDefinitions: {
7+
dataSource: {
8+
type: "string",
9+
label: "Data Source",
10+
description: "ID of the data source of the registration",
11+
async options() {
12+
const response = await this.getDataSources();
13+
return response.map(({
14+
uuid, title,
15+
}) => ({
16+
value: uuid,
17+
label: title,
18+
}));
19+
},
20+
},
21+
member: {
22+
type: "string",
23+
label: "Member",
24+
description: "ID of the member associated with this registration",
25+
async options() {
26+
const response = await this.getMembers();
27+
return response.map(({
28+
uuid, name,
29+
}) => ({
30+
value: uuid,
31+
label: name,
32+
}));
33+
},
34+
},
35+
externalId: {
36+
type: "string",
37+
label: "External ID",
38+
description: "External ID to prevent duplicate registrations",
39+
optional: true,
40+
},
41+
date: {
42+
type: "string",
43+
label: "Date",
44+
description: "Date and time of the registration in ISO 8601 format",
45+
optional: true,
46+
},
47+
productName: {
48+
type: "string",
49+
label: "Product Name",
50+
description: "Custom field representing the product name",
51+
optional: true,
52+
},
53+
unitsSold: {
54+
type: "string",
55+
label: "Units Sold",
56+
description: "Custom field representing the number of units sold",
57+
optional: true,
58+
},
59+
},
60+
methods: {
61+
_baseUrl() {
62+
return "https://app.plecto.com/api/v2";
63+
},
64+
async _makeRequest(opts = {}) {
65+
const {
66+
$ = this,
67+
path,
68+
auth,
69+
...otherOpts
70+
} = opts;
71+
return axios($, {
72+
...otherOpts,
73+
url: this._baseUrl() + path,
74+
auth: {
75+
username: `${this.$auth.username}`,
76+
password: `${this.$auth.password}`,
77+
...auth,
78+
},
79+
});
80+
},
81+
82+
async createRegistration(args = {}) {
83+
return this._makeRequest({
84+
path: "/registrations/",
85+
method: "post",
86+
...args,
87+
});
88+
},
89+
async getDataSources(args = {}) {
90+
return this._makeRequest({
91+
path: "/datasources/",
92+
...args,
93+
});
94+
},
95+
async getMembers(args = {}) {
96+
return this._makeRequest({
97+
path: "/members/",
98+
...args,
99+
});
100+
},
101+
},
102+
};

0 commit comments

Comments
 (0)