UNPKG

n8n-nodes-base

Version:

Base nodes of n8n

110 lines 4.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.description = void 0; exports.execute = execute; const utilities_1 = require("../../../../../utils/utilities"); const GenericFunctions_1 = require("../../../GenericFunctions"); const properties = [ { displayName: 'Site Name or ID', name: 'siteId', type: 'options', required: true, typeOptions: { loadOptionsMethod: 'getSites', }, default: '', 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: '', 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, description: 'Whether the item should be published on the live site', }, { displayName: 'Fields', name: 'fieldsUi', placeholder: 'Add Field', type: 'fixedCollection', typeOptions: { multipleValues: true, }, default: {}, 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', }, ], }, ], }, ]; const displayOptions = { show: { resource: ['item'], operation: ['create'], }, }; exports.description = (0, utilities_1.updateDisplayOptions)(displayOptions, properties); async function execute(items) { const returnData = []; let responseData; for (let i = 0; i < items.length; i++) { try { const collectionId = this.getNodeParameter('collectionId', i); const uiFields = this.getNodeParameter('fieldsUi.fieldValues', i, []); const live = this.getNodeParameter('live', i); const fieldData = {}; uiFields.forEach((data) => (fieldData[data.fieldId] = data.fieldValue)); const body = { fieldData, }; responseData = await GenericFunctions_1.webflowApiRequest.call(this, 'POST', `/collections/${collectionId}/items${live ? '/live' : ''}`, body); const executionData = this.helpers.constructExecutionMetaData((0, utilities_1.wrapData)(responseData.body), { itemData: { item: i } }); returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { returnData.push({ json: { message: error.message, error } }); continue; } throw error; } } return returnData; } //# sourceMappingURL=create.operation.js.map