first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,380 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const itemOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
default: 'get',
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
action: 'Create an item',
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
action: 'Delete an item',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
action: 'Get an item',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
action: 'Get many items',
|
||||
},
|
||||
{
|
||||
name: 'Update',
|
||||
value: 'update',
|
||||
action: 'Update an item',
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export const itemFields: INodeProperties[] = [
|
||||
// ----------------------------------
|
||||
// item: create
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Site Name or ID',
|
||||
name: 'siteId',
|
||||
type: 'options',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getSites',
|
||||
},
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
description:
|
||||
'ID of the site containing the collection whose items to add to. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Collection Name or ID',
|
||||
name: 'collectionId',
|
||||
type: 'options',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getCollections',
|
||||
loadOptionsDependsOn: ['siteId'],
|
||||
},
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
description:
|
||||
'ID of the collection to add an item to. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Live',
|
||||
name: 'live',
|
||||
type: 'boolean',
|
||||
required: true,
|
||||
default: false,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
description: 'Whether the item should be published on the live site',
|
||||
},
|
||||
{
|
||||
displayName: 'Fields',
|
||||
name: 'fieldsUi',
|
||||
placeholder: 'Add Field',
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Field',
|
||||
name: 'fieldValues',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Field Name or ID',
|
||||
name: 'fieldId',
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getFields',
|
||||
loadOptionsDependsOn: ['collectionId'],
|
||||
},
|
||||
default: '',
|
||||
description:
|
||||
'Field to set for the item to create. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Field Value',
|
||||
name: 'fieldValue',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Value to set for the item to create',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
// item: get
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Site Name or ID',
|
||||
name: 'siteId',
|
||||
type: 'options',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getSites',
|
||||
},
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['delete', 'get'],
|
||||
},
|
||||
},
|
||||
description:
|
||||
'ID of the site containing the collection whose items to operate on. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Collection Name or ID',
|
||||
name: 'collectionId',
|
||||
type: 'options',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getCollections',
|
||||
loadOptionsDependsOn: ['siteId'],
|
||||
},
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['delete', 'get'],
|
||||
},
|
||||
},
|
||||
description:
|
||||
'ID of the collection whose items to operate on. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Item ID',
|
||||
name: 'itemId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['delete', 'get'],
|
||||
},
|
||||
},
|
||||
description: 'ID of the item to operate on',
|
||||
},
|
||||
// ----------------------------------
|
||||
// item: update
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Site Name or ID',
|
||||
name: 'siteId',
|
||||
type: 'options',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getSites',
|
||||
},
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
description:
|
||||
'ID of the site containing the collection whose items to update. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Collection Name or ID',
|
||||
name: 'collectionId',
|
||||
type: 'options',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getCollections',
|
||||
loadOptionsDependsOn: ['siteId'],
|
||||
},
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
description:
|
||||
'ID of the collection whose items to update. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Item ID',
|
||||
name: 'itemId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
description: 'ID of the item to update',
|
||||
},
|
||||
{
|
||||
displayName: 'Live',
|
||||
name: 'live',
|
||||
type: 'boolean',
|
||||
required: true,
|
||||
default: false,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
description: 'Whether the item should be published on the live site',
|
||||
},
|
||||
{
|
||||
displayName: 'Fields',
|
||||
name: 'fieldsUi',
|
||||
placeholder: 'Add Field',
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Field',
|
||||
name: 'fieldValues',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Field Name or ID',
|
||||
name: 'fieldId',
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getFields',
|
||||
loadOptionsDependsOn: ['collectionId'],
|
||||
},
|
||||
default: '',
|
||||
description:
|
||||
'Field to set for the item to update. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Field Value',
|
||||
name: 'fieldValue',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Value to set for the item to update',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
// ----------------------------------
|
||||
// item:getAll
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Site Name or ID',
|
||||
name: 'siteId',
|
||||
type: 'options',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getSites',
|
||||
},
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
description:
|
||||
'ID of the site containing the collection whose items to retrieve. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Collection Name or ID',
|
||||
name: 'collectionId',
|
||||
type: 'options',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getCollections',
|
||||
loadOptionsDependsOn: ['siteId'],
|
||||
},
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
description:
|
||||
'ID of the collection whose items to retrieve. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['getAll'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
maxValue: 100,
|
||||
},
|
||||
default: 100,
|
||||
description: 'Max number of results to return',
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,209 @@
|
||||
import {
|
||||
type IHookFunctions,
|
||||
type IWebhookFunctions,
|
||||
type IDataObject,
|
||||
type INodeType,
|
||||
type INodeTypeDescription,
|
||||
type IWebhookResponseData,
|
||||
type INodeTypeBaseDescription,
|
||||
NodeConnectionTypes,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { getSites, webflowApiRequest } from '../GenericFunctions';
|
||||
|
||||
export class WebflowTriggerV1 implements INodeType {
|
||||
description: INodeTypeDescription;
|
||||
|
||||
constructor(baseDescription: INodeTypeBaseDescription) {
|
||||
this.description = {
|
||||
...baseDescription,
|
||||
displayName: 'Webflow Trigger',
|
||||
name: 'webflowTrigger',
|
||||
icon: 'file:webflow.svg',
|
||||
group: ['trigger'],
|
||||
version: 1,
|
||||
description: 'Handle Webflow events via webhooks',
|
||||
defaults: {
|
||||
name: 'Webflow Trigger',
|
||||
},
|
||||
|
||||
inputs: [],
|
||||
outputs: [NodeConnectionTypes.Main],
|
||||
credentials: [
|
||||
{
|
||||
name: 'webflowApi',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
authentication: ['accessToken'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'webflowOAuth2Api',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
authentication: ['oAuth2'],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
webhooks: [
|
||||
{
|
||||
name: 'default',
|
||||
httpMethod: 'POST',
|
||||
responseMode: 'onReceived',
|
||||
path: 'webhook',
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Authentication',
|
||||
name: 'authentication',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Access Token',
|
||||
value: 'accessToken',
|
||||
},
|
||||
{
|
||||
name: 'OAuth2',
|
||||
value: 'oAuth2',
|
||||
},
|
||||
],
|
||||
default: 'accessToken',
|
||||
},
|
||||
{
|
||||
displayName: 'Site Name or ID',
|
||||
name: 'site',
|
||||
type: 'options',
|
||||
required: true,
|
||||
default: '',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getSites',
|
||||
},
|
||||
description:
|
||||
'Site that will trigger the events. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Event',
|
||||
name: 'event',
|
||||
type: 'options',
|
||||
required: true,
|
||||
options: [
|
||||
{
|
||||
name: 'Collection Item Created',
|
||||
value: 'collection_item_created',
|
||||
},
|
||||
{
|
||||
name: 'Collection Item Deleted',
|
||||
value: 'collection_item_deleted',
|
||||
},
|
||||
{
|
||||
name: 'Collection Item Updated',
|
||||
value: 'collection_item_changed',
|
||||
},
|
||||
{
|
||||
name: 'Ecomm Inventory Changed',
|
||||
value: 'ecomm_inventory_changed',
|
||||
},
|
||||
{
|
||||
name: 'Ecomm New Order',
|
||||
value: 'ecomm_new_order',
|
||||
},
|
||||
{
|
||||
name: 'Ecomm Order Changed',
|
||||
value: 'ecomm_order_changed',
|
||||
},
|
||||
{
|
||||
name: 'Form Submission',
|
||||
value: 'form_submission',
|
||||
},
|
||||
{
|
||||
name: 'Site Publish',
|
||||
value: 'site_publish',
|
||||
},
|
||||
],
|
||||
default: 'form_submission',
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
methods = {
|
||||
loadOptions: {
|
||||
getSites,
|
||||
},
|
||||
};
|
||||
|
||||
webhookMethods = {
|
||||
default: {
|
||||
async checkExists(this: IHookFunctions): Promise<boolean> {
|
||||
const webhookData = this.getWorkflowStaticData('node');
|
||||
const webhookUrl = this.getNodeWebhookUrl('default');
|
||||
const siteId = this.getNodeParameter('site') as string;
|
||||
|
||||
const event = this.getNodeParameter('event') as string;
|
||||
const registeredWebhooks = await webflowApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/sites/${siteId}/webhooks`,
|
||||
);
|
||||
|
||||
const webhooks = registeredWebhooks.body?.webhooks || registeredWebhooks;
|
||||
|
||||
for (const webhook of webhooks) {
|
||||
if (webhook.url === webhookUrl && webhook.triggerType === event) {
|
||||
webhookData.webhookId = webhook._id;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
async create(this: IHookFunctions): Promise<boolean> {
|
||||
const webhookUrl = this.getNodeWebhookUrl('default');
|
||||
const webhookData = this.getWorkflowStaticData('node');
|
||||
const siteId = this.getNodeParameter('site') as string;
|
||||
const event = this.getNodeParameter('event') as string;
|
||||
const endpoint = `/sites/${siteId}/webhooks`;
|
||||
const body: IDataObject = {
|
||||
site_id: siteId,
|
||||
triggerType: event,
|
||||
url: webhookUrl,
|
||||
};
|
||||
|
||||
const response = await webflowApiRequest.call(this, 'POST', endpoint, body);
|
||||
const _id = response.body?._id || response._id;
|
||||
webhookData.webhookId = _id;
|
||||
return true;
|
||||
},
|
||||
async delete(this: IHookFunctions): Promise<boolean> {
|
||||
let responseData;
|
||||
const webhookData = this.getWorkflowStaticData('node');
|
||||
const siteId = this.getNodeParameter('site') as string;
|
||||
const endpoint = `/sites/${siteId}/webhooks/${webhookData.webhookId}`;
|
||||
try {
|
||||
responseData = await webflowApiRequest.call(this, 'DELETE', endpoint);
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
const deleted = responseData.body?.deleted || responseData.deleted;
|
||||
if (!deleted) {
|
||||
return false;
|
||||
}
|
||||
delete webhookData.webhookId;
|
||||
return true;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
|
||||
const req = this.getRequestObject();
|
||||
return {
|
||||
workflowData: [this.helpers.returnJsonArray(req.body as IDataObject[])],
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,258 @@
|
||||
import {
|
||||
type IExecuteFunctions,
|
||||
type IDataObject,
|
||||
type INodeTypeBaseDescription,
|
||||
type INodeExecutionData,
|
||||
type INodeType,
|
||||
type INodeTypeDescription,
|
||||
NodeConnectionTypes,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { itemFields, itemOperations } from './ItemDescription';
|
||||
import {
|
||||
webflowApiRequest,
|
||||
webflowApiRequestAllItems,
|
||||
getSites,
|
||||
getCollections,
|
||||
getFields,
|
||||
} from '../GenericFunctions';
|
||||
|
||||
export class WebflowV1 implements INodeType {
|
||||
description: INodeTypeDescription;
|
||||
|
||||
constructor(baseDescription: INodeTypeBaseDescription) {
|
||||
this.description = {
|
||||
...baseDescription,
|
||||
version: 1,
|
||||
description: 'Consume the Webflow API',
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
defaults: {
|
||||
name: 'Webflow',
|
||||
},
|
||||
inputs: [NodeConnectionTypes.Main],
|
||||
outputs: [NodeConnectionTypes.Main],
|
||||
credentials: [
|
||||
{
|
||||
name: 'webflowApi',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
authentication: ['accessToken'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'webflowOAuth2Api',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
authentication: ['oAuth2'],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Authentication',
|
||||
name: 'authentication',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Access Token',
|
||||
value: 'accessToken',
|
||||
},
|
||||
{
|
||||
name: 'OAuth2',
|
||||
value: 'oAuth2',
|
||||
},
|
||||
],
|
||||
default: 'accessToken',
|
||||
},
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
options: [
|
||||
{
|
||||
name: 'Item',
|
||||
value: 'item',
|
||||
},
|
||||
],
|
||||
default: 'item',
|
||||
},
|
||||
...itemOperations,
|
||||
...itemFields,
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
methods = {
|
||||
loadOptions: {
|
||||
getSites,
|
||||
getCollections,
|
||||
getFields,
|
||||
},
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const items = this.getInputData();
|
||||
|
||||
const resource = this.getNodeParameter('resource', 0);
|
||||
const operation = this.getNodeParameter('operation', 0);
|
||||
let responseData;
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
try {
|
||||
if (resource === 'item') {
|
||||
// *********************************************************************
|
||||
// item
|
||||
// *********************************************************************
|
||||
|
||||
// https://developers.webflow.com/#item-model
|
||||
|
||||
if (operation === 'create') {
|
||||
// ----------------------------------
|
||||
// item: create
|
||||
// ----------------------------------
|
||||
|
||||
// https://developers.webflow.com/#create-new-collection-item
|
||||
|
||||
const collectionId = this.getNodeParameter('collectionId', i) as string;
|
||||
|
||||
const properties = this.getNodeParameter(
|
||||
'fieldsUi.fieldValues',
|
||||
i,
|
||||
[],
|
||||
) as IDataObject[];
|
||||
|
||||
const live = this.getNodeParameter('live', i) as boolean;
|
||||
|
||||
const fields = {} as IDataObject;
|
||||
|
||||
properties.forEach((data) => (fields[data.fieldId as string] = data.fieldValue));
|
||||
|
||||
const body: IDataObject = {
|
||||
fields,
|
||||
};
|
||||
|
||||
responseData = await webflowApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/collections/${collectionId}/items`,
|
||||
body,
|
||||
{ live },
|
||||
);
|
||||
} else if (operation === 'delete') {
|
||||
// ----------------------------------
|
||||
// item: delete
|
||||
// ----------------------------------
|
||||
|
||||
// https://developers.webflow.com/#remove-collection-item
|
||||
|
||||
const collectionId = this.getNodeParameter('collectionId', i) as string;
|
||||
const itemId = this.getNodeParameter('itemId', i) as string;
|
||||
responseData = await webflowApiRequest.call(
|
||||
this,
|
||||
'DELETE',
|
||||
`/collections/${collectionId}/items/${itemId}`,
|
||||
);
|
||||
} else if (operation === 'get') {
|
||||
// ----------------------------------
|
||||
// item: get
|
||||
// ----------------------------------
|
||||
|
||||
// https://developers.webflow.com/#get-single-item
|
||||
|
||||
const collectionId = this.getNodeParameter('collectionId', i) as string;
|
||||
const itemId = this.getNodeParameter('itemId', i) as string;
|
||||
responseData = await webflowApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/collections/${collectionId}/items/${itemId}`,
|
||||
);
|
||||
responseData = responseData.items;
|
||||
} else if (operation === 'getAll') {
|
||||
// ----------------------------------
|
||||
// item: getAll
|
||||
// ----------------------------------
|
||||
|
||||
// https://developers.webflow.com/#get-all-items-for-a-collection
|
||||
|
||||
const returnAll = this.getNodeParameter('returnAll', 0);
|
||||
const collectionId = this.getNodeParameter('collectionId', i) as string;
|
||||
const qs: IDataObject = {};
|
||||
|
||||
if (returnAll) {
|
||||
responseData = await webflowApiRequestAllItems.call(
|
||||
this,
|
||||
'GET',
|
||||
`/collections/${collectionId}/items`,
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
} else {
|
||||
qs.limit = this.getNodeParameter('limit', 0);
|
||||
responseData = await webflowApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/collections/${collectionId}/items`,
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
responseData = responseData.items;
|
||||
}
|
||||
} else if (operation === 'update') {
|
||||
// ----------------------------------
|
||||
// item: update
|
||||
// ----------------------------------
|
||||
|
||||
// https://developers.webflow.com/#update-collection-item
|
||||
|
||||
const collectionId = this.getNodeParameter('collectionId', i) as string;
|
||||
|
||||
const itemId = this.getNodeParameter('itemId', i) as string;
|
||||
|
||||
const properties = this.getNodeParameter(
|
||||
'fieldsUi.fieldValues',
|
||||
i,
|
||||
[],
|
||||
) as IDataObject[];
|
||||
|
||||
const live = this.getNodeParameter('live', i) as boolean;
|
||||
|
||||
const fields = {} as IDataObject;
|
||||
|
||||
properties.forEach((data) => (fields[data.fieldId as string] = data.fieldValue));
|
||||
|
||||
const body: IDataObject = {
|
||||
fields,
|
||||
};
|
||||
|
||||
responseData = await webflowApiRequest.call(
|
||||
this,
|
||||
'PUT',
|
||||
`/collections/${collectionId}/items/${itemId}`,
|
||||
body,
|
||||
{ live },
|
||||
);
|
||||
}
|
||||
}
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
returnData.push(...executionData);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ json: { error: error.message } });
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
return [returnData];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user