UNPKG

n8n-nodes-rd-station-crm

Version:

n8n community node for RD Station CRM: API v1 (private token) and API v2 (OAuth2) — contacts, deals, organizations, tasks, notes, pipelines, stages, products, custom fields, sources, campaigns, loss reasons, users, teams and a real webhook trigger.

58 lines 2.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RD_CRM_V2_BASE_URL = void 0; exports.rdCrmV2Request = rdCrmV2Request; exports.rdCrmV2RequestAllItems = rdCrmV2RequestAllItems; const n8n_workflow_1 = require("n8n-workflow"); exports.RD_CRM_V2_BASE_URL = 'https://api.rd.services/crm/v2'; /** * Make a single authenticated request to the RD Station CRM v2 API (OAuth2). * Request bodies are wrapped in a JSON:API `{ data: ... }` envelope. */ async function rdCrmV2Request(method, endpoint, body = {}, qs = {}) { const options = { method, baseURL: exports.RD_CRM_V2_BASE_URL, url: endpoint, qs, json: true, }; if (Object.keys(body).length) { options.body = { data: body }; } if (!Object.keys(qs).length) { delete options.qs; } try { return await this.helpers.httpRequestWithAuthentication.call(this, 'rdStationCrmOAuth2Api', options); } catch (error) { throw new n8n_workflow_1.NodeApiError(this.getNode(), error); } } /** * Fetch every page of a v2 list endpoint by following `links.next` until it is absent. * Each `links.next` URL already carries the active filter/sort/page params. */ async function rdCrmV2RequestAllItems(endpoint, qs = {}) { const returnData = []; let response = await rdCrmV2Request.call(this, 'GET', endpoint, {}, qs); returnData.push(...(response?.data ?? [])); let next = response?.links?.next; let guard = 0; const maxPages = 1000; while (next && guard < maxPages) { guard += 1; // Re-issue the same endpoint with the next page's query params. const parsed = new URL(next); const nextQs = {}; parsed.searchParams.forEach((value, key) => { nextQs[key] = value; }); response = await rdCrmV2Request.call(this, 'GET', endpoint, {}, nextQs); returnData.push(...(response?.data ?? [])); next = response?.links?.next; } return returnData; } //# sourceMappingURL=v2.js.map