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
57 changes: 57 additions & 0 deletions components/attio/actions/create-note/create-note.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import attio from "../../attio.app.mjs";

export default {
key: "attio-create-note",
name: "Create Note",
description: "Creates a new note for a given record. The note will be linked to the specified record. [See the documentation](https://developers.attio.com/reference/post_v2-notes)",
version: "0.0.1",
type: "action",
props: {
attio,
parentObject: {
propDefinition: [
attio,
"objectId",
],
label: "Parent Object ID",
description: "The ID of the parent object the note belongs to",
},
parentRecordId: {
propDefinition: [
attio,
"recordId",
(c) => ({
objectId: c.parentObject,
}),
],
label: "Parent Record ID",
description: "The ID of the parent record the note belongs to",
},
title: {
type: "string",
label: "Title",
description: "The note title",
},
content: {
type: "string",
label: "Content",
description: "The content of the note",
},
},
async run({ $ }) {
const response = await this.attio.createNote({
$,
data: {
data: {
parent_object: this.parentObject,
parent_record_id: this.parentRecordId,
title: this.title,
format: "plaintext",
content: this.content,
},
},
});
$.export("$summary", `Successfully created note with ID: ${response.data.id.note_id}`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import attio from "../../attio.app.mjs";
import utils from "../../common/utils.mjs";

export default {
key: "attio-create-update-record",
name: "Create or Update Record",
description: "Creates or updates a specific record such as a person or a deal. If the record already exists, it's updated. Otherwise, a new record is created. [See the documentation](https://developers.attio.com/reference/put_v2-objects-object-records)",
version: "0.0.1",
type: "action",
props: {
attio,
objectId: {
propDefinition: [
attio,
"objectId",
],
},
attributeId: {
propDefinition: [
attio,
"attributeId",
(c) => ({
objectId: c.objectId,
}),
],
reloadProps: true,
},
},
async additionalProps() {
const props = {};
if (!this.attributeId) {
return props;
}
const attributes = await this.getRelevantAttributes();
for (const attribute of attributes) {
props[attribute.id.attribute_id] = {
type: attribute.is_multiselect
? "string[]"
: "string",
label: attribute.title,
optional: attribute.id.attribute_id !== this.attributeId && !attribute.is_required,
};
}
return props;
},
methods: {
async getRelevantAttributes() {
const stream = utils.paginate({
fn: this.attio.listAttributes,
args: {
objectId: this.objectId,
},
});
const attributes = await utils.streamIterator(stream);
return attributes.filter((a) => a.is_writable || a.id.attribute_id === this.attributeId);
},
},
async run({ $ }) {
const {
attio,
getRelevantAttributes,
objectId,
attributeId,
...values
} = this;

const attributes = await getRelevantAttributes();

const response = await attio.upsertRecord({
$,
objectId,
params: {
matching_attribute: attributeId,
},
data: {
data: {
values: utils.parseValues(attributes, values),
},
},
});
$.export("$summary", "Successfully created or updated record");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does the response specify whether it was a create or update operation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, it just returns the record, but good suggestion. The record has a created_at date, but no updated_at. If it had both, I could compare them to see if the record is newly created.

return response;
},
};
36 changes: 36 additions & 0 deletions components/attio/actions/delete-list-entry/delete-list-entry.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import attio from "../../attio.app.mjs";

export default {
key: "attio-delete-list-entry",
name: "Delete List Entry",
description: "Deletes an existing entry from a specific list. [See the documentation](https://developers.attio.com/reference/delete_v2-lists-list-entries-entry-id)",
version: "0.0.1",
type: "action",
props: {
attio,
listId: {
propDefinition: [
attio,
"listId",
],
},
entryId: {
propDefinition: [
attio,
"entryId",
(c) => ({
listId: c.listId,
}),
],
},
},
async run({ $ }) {
const response = await this.attio.deleteListEntry({
$,
listId: this.listId,
entryId: this.entryId,
});
$.export("$summary", `Successfully deleted list entry with ID: ${this.entryId}`);
return response;
},
};
189 changes: 185 additions & 4 deletions components/attio/attio.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,192 @@
import { axios } from "@pipedream/platform";
const DEFAULT_LIMIT = 20;

export default {
type: "app",
app: "attio",
propDefinitions: {},
propDefinitions: {
listId: {
type: "string",
label: "List ID",
description: "The identifier of a list",
async options() {
const { data } = await this.listLists();
return data?.map(({
id, name: label,
}) => ({
value: id.list_id,
label,
})) || [];
},
},
entryId: {
type: "string",
label: "Entry ID",
description: "The identifier of a list entry",
async options({
listId, page,
}) {
const { data } = await this.listEntries({
listId,
params: {
limit: DEFAULT_LIMIT,
offset: page * DEFAULT_LIMIT,
},
});
return data?.map(({ id }) => id.entry_id) || [];
},
},
objectId: {
type: "string",
label: "Object ID",
description: "The identifier of an object",
async options() {
const { data } = await this.listObjects();
return data?.map(({
id, singular_noun: label,
}) => ({
value: id.object_id,
label,
})) || [];
},
},
recordId: {
type: "string",
label: "Record ID",
description: "Identifier of a record",
async options({
objectId, page,
}) {
const { data } = await this.listRecords({
objectId,
params: {
limit: DEFAULT_LIMIT,
offset: page * DEFAULT_LIMIT,
},
});
return data?.map(({ id }) => id.record_id) || [];
},
},
attributeId: {
type: "string",
label: "Attribute ID",
description: "The ID or slug of the attribute to use to check if a record already exists. The attribute must be unique.",
async options({
objectId, page,
}) {
const { data } = await this.listAttributes({
objectId,
params: {
limit: DEFAULT_LIMIT,
offset: page * DEFAULT_LIMIT,
},
});
return data
?.filter((attribute) => attribute.is_unique)
?.map(({
id, title: label,
}) => ({
value: id.attribute_id,
label,
})) || [];
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.attio.com/v2";
},
_makeRequest({
$ = this,
path,
...opts
}) {
return axios($, {
url: `${this._baseUrl()}${path}`,
headers: {
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
},
...opts,
});
},
createWebhook(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/webhooks",
...opts,
});
},
deleteWebhook({
hookId, ...opts
}) {
return this._makeRequest({
method: "DELETE",
path: `/webhooks/${hookId}`,
...opts,
});
},
listLists(opts = {}) {
return this._makeRequest({
path: "/lists",
...opts,
});
},
listEntries({
listId, ...opts
}) {
return this._makeRequest({
method: "POST",
path: `/lists/${listId}/entries/query`,
...opts,
});
},
listObjects(opts = {}) {
return this._makeRequest({
path: "/objects",
...opts,
});
},
listRecords({
objectId, ...opts
}) {
return this._makeRequest({
method: "POST",
path: `/objects/${objectId}/records/query`,
...opts,
});
},
listAttributes({
objectId, ...opts
}) {
return this._makeRequest({
path: `/objects/${objectId}/attributes`,
...opts,
});
},
createNote(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/notes",
...opts,
});
},
upsertRecord({
objectId, ...opts
}) {
return this._makeRequest({
method: "PUT",
path: `/objects/${objectId}/records`,
...opts,
});
},
deleteListEntry({
listId, entryId, ...opts
}) {
return this._makeRequest({
method: "DELETE",
path: `/lists/${listId}/entries/${entryId}`,
...opts,
});
},
},
};
Loading
Loading