diff --git a/packages/nodes-base/nodes/Webflow/WebflowTrigger.node.ts b/packages/nodes-base/nodes/Webflow/WebflowTrigger.node.ts index 94519e2328..31ef2c4a40 100644 --- a/packages/nodes-base/nodes/Webflow/WebflowTrigger.node.ts +++ b/packages/nodes-base/nodes/Webflow/WebflowTrigger.node.ts @@ -117,9 +117,57 @@ export class WebflowTrigger implements INodeType { name: 'Site Publish', value: 'site_publish', }, + { + name: 'Collection Item Created', + value: 'collection_item_created', + }, + { + name: 'Collection Item Updated', + value: 'collection_item_changed', + }, + { + name: 'Collection Item Deleted', + value: 'collection_item_deleted', + }, ], default: 'form_submission', }, + { + displayName: 'All collections', + name: 'allCollections', + type: 'boolean', + required: false, + default: true, + description: 'Receive events from all collections', + }, + { + displayName: 'Collection', + name: 'collection', + type: 'options', + required: false, + default: '', + typeOptions: { + loadOptionsMethod: 'getCollections', + loadOptionsDependsOn: [ + 'site', + ], + }, + description: 'Collection that will trigger the events', + displayOptions: { + show: { + event: [ + 'collection_item_created', + 'collection_item_changed', + 'collection_item_deleted', + ], + }, + hide: { + allCollections: [ + true, + ], + }, + }, + }, ], }; @@ -140,6 +188,18 @@ export class WebflowTrigger implements INodeType { } return returnData; }, + async getCollections(this: ILoadOptionsFunctions): Promise { + const returnData: INodePropertyOptions[] = []; + const siteId = this.getCurrentNodeParameter('site'); + const collections = await webflowApiRequest.call(this, 'GET', `/sites/${siteId}/collections`); + for (const collection of collections) { + returnData.push({ + name: collection.name, + value: collection._id, + }); + } + return returnData; + }, }, }; @@ -165,6 +225,8 @@ export class WebflowTrigger implements INodeType { const webhookData = this.getWorkflowStaticData('node'); const siteId = this.getNodeParameter('site') as string; const event = this.getNodeParameter('event') as string; + const collection = this.getNodeParameter('collection') as string; + const allCollections = this.getNodeParameter('allCollections') as boolean; const endpoint = `/sites/${siteId}/webhooks`; const body: IDataObject = { site_id: siteId, @@ -172,6 +234,11 @@ export class WebflowTrigger implements INodeType { url: webhookUrl, }; + if(event.startsWith('collection') && !allCollections) { + body.filter = { + '_cid': collection, + }; + } const { _id } = await webflowApiRequest.call(this, 'POST', endpoint, body); webhookData.webhookId = _id; return true;