2023-03-09 09:13:15 -08:00
|
|
|
import type {
|
|
|
|
IExecuteFunctions,
|
|
|
|
IHookFunctions,
|
|
|
|
IDataObject,
|
|
|
|
ILoadOptionsFunctions,
|
|
|
|
IPairedItemData,
|
2024-02-14 07:29:09 -08:00
|
|
|
IHttpRequestMethods,
|
|
|
|
IRequestOptions,
|
2023-03-09 09:13:15 -08:00
|
|
|
} from 'n8n-workflow';
|
2021-11-05 10:37:50 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Make an authenticated API request to Bubble.
|
|
|
|
*/
|
|
|
|
export async function dropcontactApiRequest(
|
|
|
|
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
|
2024-02-14 07:29:09 -08:00
|
|
|
method: IHttpRequestMethods,
|
2021-11-05 10:37:50 -07:00
|
|
|
endpoint: string,
|
|
|
|
body: IDataObject,
|
|
|
|
qs: IDataObject,
|
|
|
|
) {
|
2024-02-14 07:29:09 -08:00
|
|
|
const options: IRequestOptions = {
|
2021-11-05 10:37:50 -07:00
|
|
|
method,
|
|
|
|
uri: `https://api.dropcontact.io${endpoint}`,
|
|
|
|
qs,
|
|
|
|
body,
|
|
|
|
json: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!Object.keys(body).length) {
|
|
|
|
delete options.body;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Object.keys(qs).length) {
|
|
|
|
delete options.qs;
|
|
|
|
}
|
|
|
|
|
2024-01-17 07:08:50 -08:00
|
|
|
return await this.helpers.requestWithAuthentication.call(this, 'dropcontactApi', options);
|
2021-11-05 10:37:50 -07:00
|
|
|
}
|
2023-01-31 11:39:20 -08:00
|
|
|
|
|
|
|
export function mapPairedItemsFrom<T>(iterable: Iterable<T> | ArrayLike<T>): IPairedItemData[] {
|
|
|
|
return Array.from(iterable, (_, i) => i).map((index) => {
|
|
|
|
return {
|
|
|
|
item: index,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|