UNPKG

@skriptfabrik/n8n-nodes-otto-market

Version:
43 lines 1.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ottoMarketApiRequest = ottoMarketApiRequest; const n8n_workflow_1 = require("n8n-workflow"); async function ottoMarketApiRequest(requestData, itemIndex) { const credentialIdentifier = 'ottoMarketApi'; const baseUrl = 'https://api.otto.market'; const paginationData = { continue: `={{ Boolean($response?.body?.links?.find(link => link.rel === 'next')) }}`, request: { url: `=${baseUrl}{{ $response?.body?.links.find(l => l.rel === 'next')?.href ?? '${requestData.uri}' }}`, }, requestInterval: 25, }; const baseOptions = { json: true, }; const baseHeaders = { Accept: 'application/json', }; let responseData; try { const response = await this.helpers.requestWithAuthenticationPaginated.call(this, { ...baseOptions, headers: { ...baseHeaders, }, method: requestData.method, body: requestData.body, }, itemIndex, paginationData, credentialIdentifier); response.forEach((r) => { if (r['statusCode'] >= 400) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), JSON.stringify(r['body'])); } }); responseData = response.map((val) => val['body']); } catch (error) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), error); } return responseData; } //# sourceMappingURL=GenericFunctions.js.map