Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
52 changes: 45 additions & 7 deletions components/zoho_crm/actions/common/common-objects.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,33 @@ export default {
&& !field.system_mandatory
&& field.operation_type[`api_${type}`]
&& ![
"picklist",
"lookup",
"ownerlookup",
"profileimage",
].includes(field.data_type));
},
getType(dataType) {
getType({
data_type: dataType, json_type: jsonType,
}) {
let type;
switch (dataType) {
case "boolean":
return "boolean";
type = "boolean";
break;
case "integer":
return "integer";
type = "integer";
break;
case "bigint":
return "integer";
type = "integer";
break;
default:
return "string";
type = "string";
break;
};
if (jsonType === "jsonarray") {
return `${type}[]`;
}
return type;
},
getRequiredProps(moduleType, type = "create") {
let props = {};
Expand Down Expand Up @@ -138,12 +148,40 @@ export default {
const { fields } = await this.listFields(moduleType);
for (const field of this.filterFields(fields, type)) {
props[field.api_name] = {
type: this.getType(field.data_type),
type: this.getType(field),
label: field.display_label,
optional: true,
};
if (field.pick_list_values?.length) {
props[field.api_name].options = field.pick_list_values.map(({
display_value: label, actual_value: value,
}) => ({
value,
label,
}));
}
}
return props;
},
parseFields(fields) {
if (!fields) {
return;
}
for (const [
key,
value,
] of Object.entries(fields)) {
try {
if (typeof value === "string") {
fields[key] = typeof JSON.parse(value) === "number"
? value
: JSON.parse(value);
}
} catch {
fields[key] = value;
}
}
return fields;
},
},
};
13 changes: 10 additions & 3 deletions components/zoho_crm/actions/create-object/create-object.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import common from "../common/common-objects.mjs";
import { ConfigurationError } from "@pipedream/platform";

export default {
...common,
key: "zoho_crm-create-object",
name: "Create Object",
description: "Create a new object/module entry. [See the documentation](https://www.zoho.com/crm/developer/docs/api/v2/insert-records.html)",
version: "0.3.2",
version: "0.3.3",
type: "action",
async additionalProps() {
const requiredProps = this.getRequiredProps(this.moduleType);
Expand Down Expand Up @@ -53,12 +54,18 @@ export default {
});
const objectData = {
data: [
object,
this.parseFields(object),
],
};
const res = await zohoCrm.createObject(moduleType, objectData, $);
if (res.data[0].details.id) {

if (res.data[0].code === "SUCCESS") {
$.export("$summary", `Successfully created new object with ID ${res.data[0].details.id}.`);
} else {
if (res.data[0].code === "INVALID_DATA") {
throw new ConfigurationError(`Error: Invalid data for field '${res.data[0].details.api_name}'. Expected data type: ${res.data[0].details.expected_data_type}`);
}
throw new ConfigurationError(res.data[0].message);
}
return res;
},
Expand Down
19 changes: 14 additions & 5 deletions components/zoho_crm/actions/update-object/update-object.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import zohoCrm from "../../zoho_crm.app.mjs";
import common from "../common/common-objects.mjs";
import { ConfigurationError } from "@pipedream/platform";

export default {
...common,
key: "zoho_crm-update-object",
name: "Update Object",
description: "Updates existing entities in the module. [See the documentation](https://www.zoho.com/crm/developer/docs/api/v2/update-records.html)",
version: "0.3.2",
version: "0.3.3",
type: "action",
props: {
...common.props,
Expand Down Expand Up @@ -58,13 +59,21 @@ export default {
...otherProps,
});

const response = await zohoCrm.updateObject(
const res = await zohoCrm.updateObject(
moduleType,
recordId,
object,
this.parseFields(object),
$,
);
$.export("$summary", `Successfully updated object with ID ${recordId}.`);
return response;

if (res.data[0].code === "SUCCESS") {
$.export("$summary", `Successfully updated object with ID ${recordId}.`);
} else {
if (res.data[0].code === "INVALID_DATA") {
throw new ConfigurationError(`Error: Invalid data for field '${res.data[0].details.api_name}'. Expected data type: ${res.data[0].details.expected_data_type}`);
}
throw new ConfigurationError(res.data[0].message);
}
return res;
},
};
4 changes: 2 additions & 2 deletions components/zoho_crm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/zoho_crm",
"version": "0.5.2",
"version": "0.5.3",
"description": "Pipedream Zoho CRM Components",
"main": "zoho_crm.app.mjs",
"keywords": [
Expand All @@ -10,7 +10,7 @@
"homepage": "https://pipedream.com/apps/zoho_crm",
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"dependencies": {
"@pipedream/platform": "^1.2.0",
"@pipedream/platform": "^3.0.3",
"crypto": "^1.0.1",
"lodash.sortby": "^4.7.0"
},
Expand Down
4 changes: 2 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading