2023-03-09 09:13:15 -08:00
|
|
|
import type {
|
|
|
|
IDataObject,
|
|
|
|
IExecuteFunctions,
|
|
|
|
IHookFunctions,
|
2024-02-14 07:29:09 -08:00
|
|
|
IHttpRequestMethods,
|
2023-03-09 09:13:15 -08:00
|
|
|
ILoadOptionsFunctions,
|
2024-02-14 07:29:09 -08:00
|
|
|
IRequestOptions,
|
2023-03-09 09:13:15 -08:00
|
|
|
} 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,
|
2024-02-14 07:29:09 -08:00
|
|
|
method: IHttpRequestMethods,
|
2022-08-17 08:50:24 -07:00
|
|
|
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
|
|
|
|
2024-02-14 07:29:09 -08:00
|
|
|
const options: IRequestOptions = {
|
2019-07-12 08:54:15 -07:00
|
|
|
method,
|
|
|
|
body,
|
|
|
|
qs: query,
|
|
|
|
uri: `https://api.trello.com/1/${endpoint}`,
|
|
|
|
json: true,
|
|
|
|
};
|
|
|
|
|
2024-02-22 06:44:06 -08:00
|
|
|
if (method === 'GET') {
|
|
|
|
delete options.body;
|
|
|
|
}
|
|
|
|
|
2024-01-17 07:08:50 -08:00
|
|
|
return await 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,
|
2024-02-14 07:29:09 -08:00
|
|
|
method: IHttpRequestMethods,
|
2022-08-17 08:50:24 -07:00
|
|
|
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;
|
|
|
|
}
|