fix(n8n Node): fix resource locator not returning all items (#4248)

This commit is contained in:
Jonathan Bennetts
2022-10-19 16:51:09 +01:00
committed by GitHub
parent 971c2c0aed
commit ed4dcbb5dd
2 changed files with 30 additions and 5 deletions

View File

@@ -24,7 +24,8 @@ export async function apiRequest(
endpoint: string,
body: object,
query?: IDataObject,
): Promise<unknown> {
// tslint:disable-next-line:no-any
): Promise<any> {
query = query || {};
type N8nApiCredentials = {
@@ -39,7 +40,7 @@ export async function apiRequest(
method,
body,
qs: query,
uri: `${baseUrl}/${endpoint}`,
uri: `${baseUrl.replace(new RegExp('/$'), '')}/${endpoint}`,
json: true,
};
@@ -53,6 +54,30 @@ export async function apiRequest(
}
}
export async function apiRequestAllItems(
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
method: string,
endpoint: string,
body: object,
query?: IDataObject,
// tslint:disable-next-line:no-any
): Promise<any> {
query = query || {};
const returnData: IDataObject[] = [];
let nextCursor: string | undefined = undefined;
let responseData;
do {
query.cursor = nextCursor;
query.limit = 100;
responseData = await apiRequest.call(this, method, endpoint, body, query);
returnData.push.apply(returnData, responseData.data);
nextCursor = responseData.nextCursor as string | undefined;
} while (nextCursor);
return returnData;
}
/**
* Get a cursor-based paginator to use with n8n 'getAll' type endpoints.
*