From 541b348fc89740c155dfe4bece3fe3d1c780cc8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Tue, 2 Mar 2021 12:51:30 -0300 Subject: [PATCH] :hammer: Fix pagination --- .../nodes-base/nodes/Instagram/GenericFunctions.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/nodes-base/nodes/Instagram/GenericFunctions.ts b/packages/nodes-base/nodes/Instagram/GenericFunctions.ts index ac293d478b..5eed215ed5 100644 --- a/packages/nodes-base/nodes/Instagram/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Instagram/GenericFunctions.ts @@ -17,6 +17,7 @@ export async function instagramApiRequest( endpoint: string, qs: IDataObject = {}, body: IDataObject = {}, + uri = '', ) { const options: OptionsWithUri = { method, @@ -25,7 +26,7 @@ export async function instagramApiRequest( }, qs, body, - uri: `https://graph.instagram.com${endpoint}`, + uri: uri || `https://graph.instagram.com${endpoint}`, json: true, }; @@ -65,15 +66,20 @@ export async function instagramApiRequestAllItems( const returnAll = this.getNodeParameter('returnAll', 0, false) as boolean; const limit = this.getNodeParameter('limit', 0, 0) as number; + let uri = ''; + do { - responseData = await instagramApiRequest.call(this, method, endpoint, qs, body); + responseData = await instagramApiRequest.call(this, method, endpoint, qs, body, uri); + returnData.push(...responseData.data); if (!returnAll && returnData.length > limit) { return responseData.data.slice(0, limit); } - } while (responseData.next); + uri = responseData.paging.next; + + } while (responseData.paging.next); return returnData; }