UNPKG

@jacobwoodward/n8n-nodes-smartsuite

Version:

n8n community node for SmartSuite - Interact with SmartSuite's API to manage records, search data, and perform operations on your SmartSuite solutions

67 lines 2.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.smartSuiteApiRequest = exports.formatDateField = void 0; function formatDateField(startDate, endDate, includeStartTime = true, includeEndTime = true) { return { from_date: { date: startDate, include_time: includeStartTime, }, to_date: { date: endDate, include_time: includeEndTime, }, }; } exports.formatDateField = formatDateField; async function smartSuiteApiRequest(method, endpoint, body = {}, qs = {}) { var _a, _b; const credentials = await this.getCredentials("smartSuiteApi"); if (!credentials.apiKey || !credentials.accountId || !credentials.baseUrl) { throw new Error("Missing required credentials. Please check API Key, Account ID, and Base URL are provided."); } const baseUrl = credentials.baseUrl; const apiKey = credentials.apiKey; const accountId = credentials.accountId; console.log(`Making ${method} request to ${baseUrl}${endpoint}`); const options = { method, headers: { Authorization: `Token ${apiKey}`, "Content-Type": "application/json", Accept: "application/json", "ACCOUNT-ID": accountId, }, body: method !== "GET" ? body : undefined, qs, url: `${baseUrl}${endpoint}`, json: true, }; if (method !== "GET" && options.body && typeof options.body !== "string") { options.body = JSON.stringify(options.body); console.log("Request body:", options.body); } try { return await this.helpers.httpRequest(options); } catch (error) { console.log("Request failed:", { url: options.url, method: options.method, status: (_a = error.response) === null || _a === void 0 ? void 0 : _a.status, error: error.message, }); if ((_b = error.response) === null || _b === void 0 ? void 0 : _b.data) { const errorMessage = error.response.data.message || error.response.data.error || JSON.stringify(error.response.data); throw new Error(`SmartSuite API Error (${error.response.status}): ${errorMessage}`); } if (error instanceof Error) { throw new Error(`SmartSuite API Error: ${error.message}`); } throw new Error("SmartSuite API Error: Unknown error occurred"); } } exports.smartSuiteApiRequest = smartSuiteApiRequest; //# sourceMappingURL=GenericFunctions.js.map