Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions components/plecto/.gitignore

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import app from "../../plecto.app.mjs";

export default {
key: "plecto-create-registration",
name: "Create Registration",
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)",
version: "0.0.1",
type: "action",
props: {
app,
dataSource: {
propDefinition: [
app,
"dataSource",
],
},
member: {
propDefinition: [
app,
"member",
],
},
externalId: {
propDefinition: [
app,
"externalId",
],
},
date: {
propDefinition: [
app,
"date",
],
},
productName: {
propDefinition: [
app,
"productName",
],
},
unitsSold: {
propDefinition: [
app,
"unitsSold",
],
},
},
async run({ $ }) {
const response = await this.app.createRegistration({
$,
data: {
"data_source": this.dataSource,
"member": this.member,
"external_id": this.externalId,
"date": this.date,
"Product Name": this.productName,
"Units Sold": this.unitsSold,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix inconsistent field naming in the data object.

The data object uses inconsistent naming conventions - some fields use snake_case while others use title case. This could cause API errors if the Plecto API expects consistent formatting.

Please verify the expected field format from the Plecto API documentation and apply consistent naming:

 data: {
   "data_source": this.dataSource,
   "member": this.member,
   "external_id": this.externalId,
   "date": this.date,
-  "Product Name": this.productName,
-  "Units Sold": this.unitsSold,
+  "product_name": this.productName,
+  "units_sold": this.unitsSold,
 },

OR if the API expects title case for custom fields:

 data: {
-  "data_source": this.dataSource,
-  "member": this.member,
-  "external_id": this.externalId,
-  "date": this.date,
+  "Data Source": this.dataSource,
+  "Member": this.member,
+  "External ID": this.externalId,
+  "Date": this.date,
   "Product Name": this.productName,
   "Units Sold": this.unitsSold,
 },

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In components/plecto/actions/create-registration/create-registration.mjs around
lines 51 to 58, the data object has inconsistent field naming with a mix of
snake_case and title case. Check the Plecto API documentation to confirm the
expected naming convention for these fields. Then, update all keys in the data
object to use a consistent format, either all snake_case or all title case,
matching the API requirements to prevent errors.

💡 Verification agent

🧩 Analysis chain

Verify the Plecto API registration endpoint data format.

Please confirm the expected field names and structure for the registration creation endpoint to ensure the data mapping is correct.


🌐 Web query:

What are the required and optional fields for creating a registration in the Plecto API? What is the expected field naming convention (snake_case vs title case)?

💡 Result:

To create a registration in the Plecto API, certain fields are required while others are optional. The expected naming convention for fields is snake_case (all lowercase with underscores between words).

Required Fields in Plecto Registration

The following fields are required for creating a registration through the Plecto API:

  • data_source: The UUID of the Plecto data source to which you are adding the registration. This is mandatory for identifying where the registration will be stored[1][2].
  • Value: If your data source includes a custom field named "Value," this key must be present in the POST request. This is commonly the main metric or data point you are recording, but could vary if your data source uses a different custom field name[1].
  • external_id: A unique ID for the registration. This is used to identify and, if needed, update or deduplicate registrations in Plecto[2][5].
  • member_api_provider and member_api_id: These fields identify the employee related to the registration. They are required to link the data to a specific member in Plecto[2].
    • member_name: Often included for human-readable identification of the member, but the documentation implies it's not strictly mandatory if you have the provider and ID[2].

Optional Fields

  • date: The primary date of the registration in ISO 8601 format (e.g., "2022-12-31T10:22:55"). If not specified, Plecto will automatically use the current date and time at registration creation[1][2].
  • Custom fields: Any additional fields you have defined in your Plecto data source can be added. These fields must match the names and types as configured in your Plecto dashboard[2][5].

Field Naming Convention

Plecto uses snake_case for all field names in its API. This means all letters are lowercase and words are separated by underscores (e.g., "data_source", "external_id")[2][3]. This convention matches standard API practices for clarity and consistency, and no field names should be in Title Case or CamelCase.

"Here's a list of field names, types and descriptions that make up Plecto's API data model:"
| data_source | string (UUID) |
| date | ISO 8601 with timestamp |
| member_api_provider | string |
| member_api_id | string |
| member_name | string |
| external_id | string |
| | |[2]

Example Registration Payload

{
  "data_source": "your-data-source-uuid",
  "external_id": "unique-registration-id",
  "member_api_provider": "your-system-name",
  "member_api_id": "employee-id-in-your-system",
  "member_name": "Employee Name",
  "date": "2025-06-30T18:00:00",
  "Value": 100,
  "custom_field_1": "custom_value"
}

Summary:

  • Always use snake_case for field names.
  • Required: data_source, external_id, member_api_provider, member_api_id, and typically a metric field (e.g., Value).
  • Optional: date, member_name, and any custom fields defined in your data source[1][2].

Citations:


Ensure Plecto API registration payload uses correct snake_case fields

Please update the payload to match Plecto’s snake_case naming convention and include the required member identifiers:

• Replace the single "member" key with the two required fields:
member_api_provider (e.g. your system name)
member_api_id (the user’s ID in your system)
• Convert custom field names from Title Case/with spaces to snake_case, matching your data‐source definitions (e.g. "product_name", "units_sold").
• Confirm you still include the required metric field (often "Value" or your custom equivalent) if that isn’t one of these custom fields.

Proposed snippet:

   data: {
-    "data_source": this.dataSource,
-    "member": this.member,
-    "external_id": this.externalId,
-    "date": this.date,
-    "Product Name": this.productName,
-    "Units Sold": this.unitsSold,
+    data_source:          this.dataSource,
+    external_id:          this.externalId,
+    member_api_provider:  this.memberApiProvider,
+    member_api_id:        this.memberApiId,
+    date:                 this.date,
+    product_name:         this.productName,
+    units_sold:           this.unitsSold,
   },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
data: {
"data_source": this.dataSource,
"member": this.member,
"external_id": this.externalId,
"date": this.date,
"Product Name": this.productName,
"Units Sold": this.unitsSold,
},
data: {
data_source: this.dataSource,
external_id: this.externalId,
member_api_provider: this.memberApiProvider,
member_api_id: this.memberApiId,
date: this.date,
product_name: this.productName,
units_sold: this.unitsSold,
},
🤖 Prompt for AI Agents
In components/plecto/actions/create-registration/create-registration.mjs around
lines 51 to 58, the payload uses incorrect field names and structure for the
Plecto API. Replace the single "member" key with "member_api_provider" and
"member_api_id" to include required member identifiers. Change custom field
names from Title Case with spaces to snake_case, such as "product_name" and
"units_sold". Also, verify that the payload includes the required metric field
like "value" if it is not already present among these fields.

});
$.export("$summary", "Successfully created registration with ID: " + response.id);
return response;
},
};
13 changes: 0 additions & 13 deletions components/plecto/app/plecto.app.ts

This file was deleted.

102 changes: 102 additions & 0 deletions components/plecto/plecto.app.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "plecto",
propDefinitions: {
dataSource: {
type: "string",
label: "Data Source",
description: "ID of the data source of the registration",
async options() {
const response = await this.getDataSources();
return response.map(({
uuid, title,
}) => ({
value: uuid,
label: title,
}));
},
Comment on lines +11 to +19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling to the options() function.

The async options function lacks error handling, which could cause the UI to break if the API request fails.

 async options() {
-  const response = await this.getDataSources();
-  return response.map(({
-    uuid, title,
-  }) => ({
-    value: uuid,
-    label: title,
-  }));
+  try {
+    const response = await this.getDataSources();
+    return response.map(({
+      uuid, title,
+    }) => ({
+      value: uuid,
+      label: title,
+    }));
+  } catch (error) {
+    console.error("Failed to fetch data sources:", error);
+    return [];
+  }
 },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async options() {
const response = await this.getDataSources();
return response.map(({
uuid, title,
}) => ({
value: uuid,
label: title,
}));
},
async options() {
try {
const response = await this.getDataSources();
return response.map(({
uuid, title,
}) => ({
value: uuid,
label: title,
}));
} catch (error) {
console.error("Failed to fetch data sources:", error);
return [];
}
},
🤖 Prompt for AI Agents
In components/plecto/plecto.app.mjs around lines 11 to 19, the async options()
function does not handle errors from the getDataSources() call, risking UI
breakage on failure. Add a try-catch block around the await
this.getDataSources() call to catch any errors, and handle them gracefully by
returning an empty array or a fallback value. This will prevent unhandled
promise rejections and keep the UI stable if the API request fails.

},
member: {
type: "string",
label: "Member",
description: "ID of the member associated with this registration",
async options() {
const response = await this.getMembers();
return response.map(({
uuid, name,
}) => ({
value: uuid,
label: name,
}));
},
Comment on lines +25 to +33
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling to the options() function.

Similar to the dataSource prop, this async options function needs error handling.

 async options() {
-  const response = await this.getMembers();
-  return response.map(({
-    uuid, name,
-  }) => ({
-    value: uuid,
-    label: name,
-  }));
+  try {
+    const response = await this.getMembers();
+    return response.map(({
+      uuid, name,
+    }) => ({
+      value: uuid,
+      label: name,
+    }));
+  } catch (error) {
+    console.error("Failed to fetch members:", error);
+    return [];
+  }
 },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async options() {
const response = await this.getMembers();
return response.map(({
uuid, name,
}) => ({
value: uuid,
label: name,
}));
},
async options() {
try {
const response = await this.getMembers();
return response.map(({
uuid, name,
}) => ({
value: uuid,
label: name,
}));
} catch (error) {
console.error("Failed to fetch members:", error);
return [];
}
},
🤖 Prompt for AI Agents
In components/plecto/plecto.app.mjs around lines 25 to 33, the async options()
function lacks error handling which can cause unhandled promise rejections. Wrap
the await call to this.getMembers() in a try-catch block, and in the catch block
handle or log the error appropriately. Ensure the function returns a sensible
default or empty array if an error occurs to maintain stability.

},
Comment on lines +21 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Update member prop to support Plecto API requirements.

Based on the Plecto API documentation, member identification requires separate member_api_provider and member_api_id fields rather than a single member field.

Consider splitting this into two separate props:

-    member: {
-      type: "string",
-      label: "Member",
-      description: "ID of the member associated with this registration",
-      async options() {
-        const response = await this.getMembers();
-        return response.map(({
-          uuid, name,
-        }) => ({
-          value: uuid,
-          label: name,
-        }));
-      },
-    },
+    memberApiProvider: {
+      type: "string",
+      label: "Member API Provider",
+      description: "The system name that provides the member ID",
+    },
+    memberApiId: {
+      type: "string",
+      label: "Member API ID", 
+      description: "The member's ID in your system",
+    },

Or keep the existing structure but update the action to map the selected member UUID to the required API format.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
member: {
type: "string",
label: "Member",
description: "ID of the member associated with this registration",
async options() {
const response = await this.getMembers();
return response.map(({
uuid, name,
}) => ({
value: uuid,
label: name,
}));
},
},
memberApiProvider: {
type: "string",
label: "Member API Provider",
description: "The system name that provides the member ID",
},
memberApiId: {
type: "string",
label: "Member API ID",
description: "The member's ID in your system",
},
🤖 Prompt for AI Agents
In components/plecto/plecto.app.mjs around lines 21 to 34, the member property
currently uses a single field for member identification, but the Plecto API
requires separate fields for member_api_provider and member_api_id. To fix this,
either split the member property into two separate properties named
member_api_provider and member_api_id with appropriate types and options, or
update the existing member property and the related action logic to map the
selected member UUID into the required API format that includes both provider
and ID fields.

externalId: {
type: "string",
label: "External ID",
description: "External ID to prevent duplicate registrations",
optional: true,
},
date: {
type: "string",
label: "Date",
description: "Date and time of the registration in ISO 8601 format",
optional: true,
},
productName: {
type: "string",
label: "Product Name",
description: "Custom field representing the product name",
optional: true,
},
unitsSold: {
type: "string",
label: "Units Sold",
description: "Custom field representing the number of units sold",
optional: true,
},
},
methods: {
_baseUrl() {
return "https://app.plecto.com/api/v2";
},
async _makeRequest(opts = {}) {
const {
$ = this,
path,
auth,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: this._baseUrl() + path,
auth: {
username: `${this.$auth.username}`,
password: `${this.$auth.password}`,
...auth,
},
});
},

async createRegistration(args = {}) {
return this._makeRequest({
path: "/registrations/",
method: "post",
...args,
});
},
async getDataSources(args = {}) {
return this._makeRequest({
path: "/datasources/",
...args,
});
},
async getMembers(args = {}) {
return this._makeRequest({
path: "/members/",
...args,
});
},
},
};
Loading