-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - attio #14236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Components - attio #14236
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
} | ||
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); | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}, | ||
async run({ $ }) { | ||
const { | ||
attio, | ||
getRelevantAttributes, | ||
objectId, | ||
attributeId, | ||
...values | ||
} = this; | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the response specify whether it was a create or update operation? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
return response; | ||
}, | ||
}; |
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; | ||
}, | ||
}; |
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, | ||
})) || []; | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}, | ||
}, | ||
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, | ||
}); | ||
}, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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, | ||
}); | ||
}, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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, | ||
}); | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}, | ||
}; |
Uh oh!
There was an error while loading. Please reload this page.