2023-01-27 03:22:44 -08:00
|
|
|
import type { IExecuteFunctions, IHookFunctions, ILoadOptionsFunctions } from 'n8n-core';
|
2019-07-12 08:54:15 -07:00
|
|
|
|
2023-01-27 03:22:44 -08:00
|
|
|
import type { OptionsWithUri } from 'request';
|
2019-07-12 08:54:15 -07:00
|
|
|
|
2023-01-27 03:22:44 -08:00
|
|
|
import type { IDataObject } from 'n8n-workflow';
|
2019-07-12 08:54:15 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Make an API request to Trello
|
|
|
|
*
|
|
|
|
*/
|
2022-08-17 08:50:24 -07:00
|
|
|
export async function apiRequest(
|
|
|
|
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
|
|
|
|
method: string,
|
|
|
|
endpoint: string,
|
|
|
|
body: object,
|
|
|
|
query?: IDataObject,
|
|
|
|
): Promise<any> {
|
2023-01-19 04:37:19 -08:00
|
|
|
query = query || {};
|
2019-07-12 08:54:15 -07:00
|
|
|
|
|
|
|
const options: OptionsWithUri = {
|
|
|
|
method,
|
|
|
|
body,
|
|
|
|
qs: query,
|
|
|
|
uri: `https://api.trello.com/1/${endpoint}`,
|
|
|
|
json: true,
|
|
|
|
};
|
|
|
|
|
2022-11-22 08:57:17 -08:00
|
|
|
return this.helpers.requestWithAuthentication.call(this, 'trelloApi', options);
|
2019-07-12 08:54:15 -07:00
|
|
|
}
|
2021-01-19 06:09:03 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
export async function apiRequestAllItems(
|
|
|
|
this: IHookFunctions | IExecuteFunctions,
|
|
|
|
method: string,
|
|
|
|
endpoint: string,
|
|
|
|
body: IDataObject,
|
|
|
|
query: IDataObject = {},
|
|
|
|
): Promise<any> {
|
2021-01-19 06:09:03 -08:00
|
|
|
query.limit = 30;
|
|
|
|
|
|
|
|
query.sort = '-id';
|
|
|
|
|
|
|
|
const returnData: IDataObject[] = [];
|
|
|
|
|
|
|
|
let responseData;
|
|
|
|
|
|
|
|
do {
|
|
|
|
responseData = await apiRequest.call(this, method, endpoint, body, query);
|
2023-02-27 19:39:43 -08:00
|
|
|
returnData.push.apply(returnData, responseData as IDataObject[]);
|
2021-01-19 06:09:03 -08:00
|
|
|
if (responseData.length !== 0) {
|
|
|
|
query.before = responseData[responseData.length - 1].id;
|
|
|
|
}
|
2022-08-17 08:50:24 -07:00
|
|
|
} while (query.limit <= responseData.length);
|
2021-01-19 06:09:03 -08:00
|
|
|
|
|
|
|
return returnData;
|
|
|
|
}
|