Created
November 3, 2020 15:47
-
-
Save ganobrega/6783a0c3e6706a7397a47980e8100247 to your computer and use it in GitHub Desktop.
Get VTEX Template E-mails
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 axios = require('axios'); | |
const LIST_ENDPOINT = `https://loja.myvtex.com/api/template-render/pvt/templates/getlist`; | |
const TEMPLATE_ENDPOINT = `https://loja.myvtex.com/api/template-render/pvt/templates/`; | |
const JSON_ENDPOINT = `https://loja.myvtex.com/api/template-render/pvt/templates/json`; | |
const LIST = []; | |
const AUTH_COOKIE = | |
'VtexIdclientAutCookie=$$$$$$$$;'; | |
(async () => { | |
const { data: templates } = await axios.get(LIST_ENDPOINT, { | |
headers: { | |
Cookie: AUTH_COOKIE, | |
}, | |
}); | |
const TEMPLATES_AND_CHARGERS = Promise.all( | |
templates.map(async (template) => { | |
let attempts = 0; | |
const getTemplateJson = async () => { | |
attempts += 1; | |
try { | |
const { data } = await axios.get( | |
`${JSON_ENDPOINT}/${template.Name}`, | |
{ headers: { Cookie: AUTH_COOKIE } } | |
); | |
return { | |
template, | |
json: data, | |
}; | |
} catch (error) { | |
if (attempts <= 3) { | |
await getTemplateJson(); | |
} else { | |
return { | |
template, | |
error, | |
}; | |
} | |
} | |
}; | |
return await getTemplateJson(); | |
}) | |
); | |
console.log(await TEMPLATES_AND_CHARGERS); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment