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
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import copper from "../../copper.app.mjs";

export default {
key: "copper-associate-to-project",
name: "Associate to Project",
description: "Relates an existing project with an existing CRM object. [See the documentation](https://developer.copper.com/related-items/relate-an-existing-record-to-an-entity.html)",
version: "0.0.1",
type: "action",
props: {
copper,
projectId: {
propDefinition: [
copper,
"objectId",
() => ({
objectType: "projects",
}),
],
label: "Project ID",
description: "The ID of the project you wish to relate",
},
objectType: {
propDefinition: [
copper,
"objectType",
],
},
objectId: {
propDefinition: [
copper,
"objectId",
(c) => ({
objectType: c.objectType,
}),
],
},
},
async run({ $ }) {
const response = await this.copper.relateProjectToCrmObject({
$,
objectType: this.objectType,
objectId: this.objectId,
data: {
resource: {
id: this.projectId,
type: "project",
},
},
});
$.export("$summary", `Successfully associated Project ID ${this.projectId} with CRM ID ${this.objectId}`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import copper from "../../copper.app.mjs";
import { ConfigurationError } from "@pipedream/platform";

export default {
key: "copper-create-update-person",
name: "Create or Update Person",
description: "Creates a new person or updates an existing one based on email address. [See the documentation](https://developer.copper.com/people/create-a-new-person.html)",
version: "0.0.1",
type: "action",
props: {
copper,
email: {
type: "string",
label: "Email",
description: "Email address of the person. If email already exists, the person will be updated",
},
name: {
type: "string",
label: "Name",
description: "Name of the contact. Required if creating a new person.",
optional: true,
},
streetAddress: {
type: "string",
label: "Street Address",
description: "Street address of the person",
optional: true,
},
city: {
type: "string",
label: "City",
description: "City address of the person",
optional: true,
},
state: {
type: "string",
label: "State",
description: "State address of the person",
optional: true,
},
postalCode: {
type: "string",
label: "Postal Code",
description: "Postal code of the person",
optional: true,
},
country: {
type: "string",
label: "Country",
description: "Country of the person",
optional: true,
},
phone: {
type: "string",
label: "Phone",
description: "Phone number of the person",
optional: true,
},
},
async run({ $ }) {
let response;
const hasAddress = this.streetAddress
|| this.city
|| this.state
|| this.postalCode
|| this.country;
const data = {
emails: [
{
email: this.email,
category: "work",
},
],
name: this.name,
address: hasAddress && {
street: this.streetAddress,
city: this.city,
state: this.state,
postal_code: this.postalCode,
country: this.country,
},
phone_numbers: this.phone && [
{
number: this.phone,
category: "work",
},
],
};

// search for the person
const person = await this.copper.listObjects({
$,
objectType: "people",
data: {
emails: [
this.email,
],
},
});

if (!person?.length && !this.name) {
throw new ConfigurationError(`Person with email ${this.email} not found. Name is required for creating a new person.`);
}

// create person if not found
if (!person?.length) {
response = await this.copper.createPerson({
$,
data,
});
}
// update person if found
else {
response = await this.copper.updatePerson({
$,
personId: person[0].id,
data,
});
}

$.export("$summary", `Successfully ${person?.length
? "updated"
: "created"} person with ID: ${response.id}`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import copper from "../../copper.app.mjs";

export default {
key: "copper-create-update-project",
name: "Create or Update Project",
description: "Creates a new project or updates an existing one based on the project name. [See the documentation](https://developer.copper.com/projects/create-a-new-project.html)",
version: "0.0.1",
type: "action",
props: {
copper,
name: {
type: "string",
label: "Name",
description: "Name of the project. If a project with the specified name already exists, it will be updated",
},
details: {
type: "string",
label: "Details",
description: "Description of the Project",
optional: true,
},
assigneeId: {
propDefinition: [
copper,
"objectId",
() => ({
objectType: "users",
}),
],
label: "Assignee ID",
description: "The ID of the User that will be the owner of the Project",
optional: true,
},
status: {
propDefinition: [
copper,
"status",
],
},
tags: {
propDefinition: [
copper,
"tags",
],
},
},
async run({ $ }) {
let response;
const data = {
name: this.name,
assignee_id: this.assigneeId,
status: this.status,
tags: this.tags,
};

// search for the project
const project = await this.copper.listObjects({
$,
objectType: "projects",
data: {
name: this.name,
},
});

// create project if not found
if (!project?.length) {
response = await this.copper.createProject({
$,
data,
});
}
// update project if found
else {
response = await this.copper.updateProject({
$,
projectId: project[0].id,
data,
});
}

$.export("$summary", `Successfully ${project?.length
? "updated"
: "created"} project with ID: ${response.id}`);
return response;
},
};
36 changes: 36 additions & 0 deletions components/copper/actions/get-object/get-object.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import copper from "../../copper.app.mjs";

export default {
key: "copper-get-object",
name: "Get Object",
description: "Retrieves an existing CRM object. [See the documentation](https://developer.copper.com/account-and-users/fetch-user-by-id.html)",
version: "0.0.1",
type: "action",
props: {
copper,
objectType: {
propDefinition: [
copper,
"objectType",
],
},
objectId: {
propDefinition: [
copper,
"objectId",
(c) => ({
objectType: c.objectType,
}),
],
},
},
async run({ $ }) {
const response = await this.copper.getObject({
objectType: this.objectType,
objectId: this.objectId,
$,
});
$.export("$summary", `Successfully retrieved CRM object with ID ${this.objectId}`);
return response;
},
};
Loading
Loading