Skip to content

Instantly share code, notes, and snippets.

@Antoinebr
Created June 23, 2023 08:05
Show Gist options
  • Save Antoinebr/c0ab8929f8d1543b2356488c0c607620 to your computer and use it in GitHub Desktop.
Save Antoinebr/c0ab8929f8d1543b2356488c0c607620 to your computer and use it in GitHub Desktop.
hs-API-create-An-Email-Template.js
const axios = require('axios');
const privateAppToken = "your-private-app-token-here-dqdsqs-qsdsqdsq";
const axiosConfig = {
headers: {
authorization: `Bearer ${privateAppToken}`
}
};
const emailSource = /*HTML*/`
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Bienvenue sur mon site</title>
<style>
/* Styles spécifiques à l'e-mail */
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
background-color: #ffffff;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1 {
color: #333333;
text-align: center;
margin-top: 0;
}
p {
color: #666666;
line-height: 1.5;
}
.cta-button {
display: inline-block;
background-color: #336699;
color: #ffffff;
text-decoration: none;
padding: 10px 20px;
border-radius: 3px;
margin-top: 20px;
}
.cta-button:hover {
background-color: #254e80;
}
</style>
</head>
<body>
<div class="container">
<h1>Bienvenue sur mon site</h1>
<p>Découvrez notre incroyable sélection de produits qui sauront vous émerveiller. Que vous soyez à la recherche d'articles tendance, de services exceptionnels ou d'inspiration, notre site est l'endroit idéal pour répondre à tous vos besoins.</p>
<p>Notre équipe d'experts est engagée à vous offrir la meilleure expérience en ligne, en vous proposant des fonctionnalités innovantes et une navigation intuitive. Vous trouverez chez nous une qualité inégalée, un service client exceptionnel et des prix compétitifs.</p>
<p>Rejoignez-nous dès maintenant et découvrez tout ce que notre site a à offrir !</p>
<a class="cta-button" href="#">Découvrir</a>
</div>
</body>
</html>
`;
/**
* @name createAnEmailTemplate
* @returns {promise}
*/
const createAnEmailTemplate = async () => {
const endpoint = `https://api.hubapi.com/content/api/v2/templates`;
return axios.post(endpoint, {
"category_id": 2,
"folder": "examples",
"is_available_for_new_content": "True",
"template_type": 2,
"path":"custom/page/examples/a-new-template-true.html",
"source":emailSource
}, axiosConfig);
}
(async () => {
const res = await createAnEmailTemplate()
console.log(res.data);
})().catch(console.log);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment