Created
February 17, 2023 08:27
-
-
Save SariSaar/c866ec9802c0db39c206b5d05a3e37e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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