Created
May 2, 2024 15:32
-
-
Save enriquebeta6/0861fbd2c35f121d0a6c653e3a42485e 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
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