Skip to content

Instantly share code, notes, and snippets.

@ganobrega
Created November 3, 2020 15:47
Show Gist options
  • Save ganobrega/6783a0c3e6706a7397a47980e8100247 to your computer and use it in GitHub Desktop.
Save ganobrega/6783a0c3e6706a7397a47980e8100247 to your computer and use it in GitHub Desktop.
Get VTEX Template E-mails
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