Describe the problem/error/question
I have a simple usecase not supported by the Google Sheets node: get the list of sheets in a document.
I’ve created a new node, and that’s simple enough following the custom node recipe. However, it would be a nice contribution to the core and I could easily patch it into the GoogleSheetsV2 node.
However… it seems the maintainers are slow to incorporate contributions of this sort (see thread and related PR: Extend paypal node functions) - priorities, I get it, not judging.
If you were me, what would be best practice for my personal goals and community benefit - make it work and ideally share it:
- copy the core node wholesale into my custom node package, patch it, and release it in the meantime?
- Subclass the core node with my custom node?
- Stick with a simple node (see code below) and deploy as a custom node?
Suggestions are welcome
Information on your n8n setup
- n8n version: 1.77
- Database (default: SQLite): default
- n8n EXECUTIONS_PROCESS setting (default: own, main): main
- Running n8n via (Docker, npm, n8n cloud, desktop app): local
- Operating system: Yes
Code
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
// Prepare the data that we'll return
const returnData: INodeExecutionData[] = [];
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
try {
// Retrieve the spreadsheet ID from the current item
const spreadsheetId = this.getNodeParameter('spreadsheetId', itemIndex) as string;
const endpoint = `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}`;
const qs: IDataObject = { includeGridData: false };
const response = await this.helpers.requestOAuth2.call(this, 'googleSheetsOAuth2Api', {
method: 'GET',
uri: endpoint,
qs,
json: true,
});
const { sheets } = response;
if (Array.isArray(sheets)) {
sheets.forEach((sheet) => {
const { sheetId, title } = sheet.properties || {};
sheet;
returnData.push({
json: {
spreadsheetId,
sheetId,
title,
},
});
});
}
} catch (error) {
throw new NodeOperationError(
this.getNode(),
`Google Sheets API Error: ${(error as Error).message}`,
{
itemIndex,
},
);
}
}