Skip to content

Instantly share code, notes, and snippets.

@SariSaar
Created February 17, 2023 08:27
Show Gist options
  • Save SariSaar/c866ec9802c0db39c206b5d05a3e37e7 to your computer and use it in GitHub Desktop.
Save SariSaar/c866ec9802c0db39c206b5d05a3e37e7 to your computer and use it in GitHub Desktop.
const flexIntegrationSdk = require('sharetribe-flex-integration-sdk');
const integrationSdk = flexIntegrationSdk.createInstance({
// client information
})
let paginationLimit = null;
const getNextPage = (params, page, results = []) => integrationSdk.listings.query({...params, page}).then(resp => {
console.log('resp.data.meta', resp.data.meta)
if (!paginationLimit) {
paginationLimit = resp.data.meta.paginationLimit;
}
const newResults = [...results, ...resp.data.data];
if (page < paginationLimit) {
return getNextPage(params, page + 1, newResults);
} else {
return newResults;
}
})
// add params in the first object, e.g.
// { state: 'published' }
getNextPage({}, 1).then(results => {
// you now have all the results in a single array for further processing
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment