UNPKG

n8n-nodes-placid

Version:

n8n node to interact with Placid API for creative generation

61 lines 2.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.execute = execute; const n8n_workflow_1 = require("n8n-workflow"); async function execute(index) { try { const returnAll = this.getNodeParameter('returnAll', index, false); const additionalFields = this.getNodeParameter('additionalFields', index, {}); let allTemplates = []; let nextUrl = null; const queryParams = new URLSearchParams(); if (additionalFields.collection_id) { queryParams.append('collection_id', additionalFields.collection_id); } const baseUrl = 'https://api.placid.app/api/rest/templates'; let currentUrl = queryParams.toString() ? `${baseUrl}?${queryParams.toString()}` : baseUrl; do { const options = { method: 'GET', url: currentUrl, headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, }; const response = await this.helpers.httpRequestWithAuthentication.call(this, 'placidApi', options); let templates = []; if (response.data && Array.isArray(response.data)) { templates = response.data; } else if (Array.isArray(response)) { templates = response; } else { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Unexpected response format from Placid API', { itemIndex: index, }); } allTemplates = allTemplates.concat(templates); nextUrl = null; if (response.links && response.links.next) { nextUrl = response.links.next; } if (!returnAll) { break; } if (nextUrl) { currentUrl = nextUrl; } } while (nextUrl && returnAll); return allTemplates.map(template => ({ json: template, })); } catch (error) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Failed to list templates: ${error.message}`, { itemIndex: index, }); } } //# sourceMappingURL=getMany.operation.js.map