Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Pagination on Action Network Node [N8N-3179] #3011

Merged
merged 5 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/nodes-base/credentials/ActionNetworkApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import {
ICredentialDataDecryptedObject,
ICredentialTestRequest,
ICredentialType,
IHttpRequestOptions,
INodeProperties,
} from 'n8n-workflow';

Expand All @@ -15,4 +18,14 @@ export class ActionNetworkApi implements ICredentialType {
default: '',
},
];
test: ICredentialTestRequest = {
request: {
baseURL: 'https://actionnetwork.org/api/v2',
url: '/events?per_page=1',
},
};
async authenticate(credentials: ICredentialDataDecryptedObject, requestOptions: IHttpRequestOptions): Promise<IHttpRequestOptions> {
requestOptions.headers = { 'OSDI-API-Token': credentials.apiKey };
return requestOptions;
}
}
20 changes: 6 additions & 14 deletions packages/nodes-base/nodes/ActionNetwork/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
IDataObject,
ILoadOptionsFunctions,
NodeApiError,
NodeOperationError,
} from 'n8n-workflow';

import {
Expand Down Expand Up @@ -35,16 +34,7 @@ export async function actionNetworkApiRequest(
body: IDataObject = {},
qs: IDataObject = {},
) {
const credentials = await this.getCredentials('actionNetworkApi') as { apiKey: string } | undefined;

if (credentials === undefined) {
throw new NodeOperationError(this.getNode(), 'No credentials got returned!');
}

const options: OptionsWithUri = {
headers: {
'OSDI-API-Token': credentials.apiKey,
},
method,
body,
qs,
Expand All @@ -61,7 +51,7 @@ export async function actionNetworkApiRequest(
}

try {
return await this.helpers.request!(options);
return await this.helpers.requestWithAuthentication.call(this, 'actionNetworkApi', options);
} catch (error) {
throw new NodeApiError(this.getNode(), error);
}
Expand Down Expand Up @@ -95,13 +85,15 @@ export async function handleListing(
return returnData.slice(0, limit);
}

qs.page = responseData.page as number;
} while (responseData.total_pages && qs.page < responseData.total_pages);
if (responseData._links && responseData._links.next && responseData._links.next.href) {
const queryString = new URLSearchParams(responseData._links.next.href.split('?')[1]);
qs.page = queryString.get('page') as string;
}
} while (responseData._links && responseData._links.next);

return returnData;
}


// ----------------------------------------
// helpers
// ----------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,11 @@ export const personFields: INodeProperties[] = [
displayName: 'Limit',
name: 'limit',
type: 'number',
default: 50,
default: 25,
description: 'The number of results to return.',
typeOptions: {
minValue: 1,
maxValue: 25,
},
displayOptions: {
show: {
Expand Down