Skip to content

Commit

Permalink
fix(WooCommerce Node): Fix pagination issue with "Get All" operation (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
that-one-tom committed Apr 6, 2022
1 parent 358a683 commit c2a5e0d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/nodes-base/nodes/WooCommerce/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export async function woocommerceApiRequest(this: IHookFunctions | IExecuteFunct
uri: uri || `${credentials.url}/wp-json/wc/v3${resource}`,
json: true,
};

if (credentials.includeCredentialsInQuery === true) {
delete options.auth;
Object.assign(qs, { consumer_key: credentials.consumerKey, consumer_secret: credentials.consumerSecret });
Expand All @@ -79,7 +78,11 @@ export async function woocommerceApiRequestAllItems(this: IExecuteFunctions | IL
query.per_page = 100;
do {
responseData = await woocommerceApiRequest.call(this, method, endpoint, body, query, uri, { resolveWithFullResponse: true });
uri = responseData.headers['link'].split(';')[0].replace('<', '').replace('>', '');
const links = responseData.headers.link.split(',');
const nextLink = links.find((link: string) => link.indexOf('rel="next"') !== -1);
if (nextLink) {
uri = nextLink.split(';')[0].replace(/<(.*)>/, '$1');
}
returnData.push.apply(returnData, responseData.body);
} while (
responseData.headers['link'] !== undefined &&
Expand Down Expand Up @@ -156,7 +159,7 @@ export function setFields(fieldsToSet: IDataObject, body: IDataObject) {
} else {
body[snakeCase(fields.toString())] = fieldsToSet[fields];
}

}
}

Expand Down

0 comments on commit c2a5e0d

Please sign in to comment.