Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save enriquebeta6/0861fbd2c35f121d0a6c653e3a42485e to your computer and use it in GitHub Desktop.
Save enriquebeta6/0861fbd2c35f121d0a6c653e3a42485e to your computer and use it in GitHub Desktop.
import fs from 'fs'
async function init() {
let token = ''
const size = 1000
const schema = ''
const allDocuments = []
const accountName = ''
const fields = ['_all'].join(',')
const entity = ''
const where = ''
const authToken = ''
while (true) {
const params = token
? `_token=${token}`
: `_fields=${fields}&_schema=${schema}&_where=${where}&_size=${size}`
const response = await fetch(
`https://${accountName}.myvtex.com/api/dataentities/${entity}/scroll?${params}`,
{
headers: {
VtexIdclientAutCookie: authToken,
},
}
)
token = response.headers.get('X-VTEX-MD-TOKEN')
const documents = await response.json()
if (documents.length === 0) {
break
}
allDocuments.push(...documents)
}
fs.createWriteStream('./documents.json').write(
JSON.stringify(allDocuments, null, 4)
)
}
init()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment