fix(WooCommerce Node): Fix pagination issue with "Get All" operation (#2529)

This commit is contained in:
Tom 2022-04-06 14:05:36 +02:00 committed by GitHub
parent 358a683f38
commit c2a5e0d1b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 });
@ -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 &&