Skip to content

Instantly share code, notes, and snippets.

@hijonathan
Created February 8, 2016 16:24
Show Gist options
  • Select an option

  • Save hijonathan/310bc74d3c79aa9929eb to your computer and use it in GitHub Desktop.

Select an option

Save hijonathan/310bc74d3c79aa9929eb to your computer and use it in GitHub Desktop.
Simple node script to import blog articles into HubSpot.
{
"count": "2",
"results": [{
"name": "Post 1",
"meta_description": "A post worth reading",
"meta_keywords": "articles, tests, things",
"post_body": "<h1>Hey!</h1>\n<p>Some words and stuff!</p>",
"blog_author_id": 40000001,
"publish_date": 1454948561,
"slug": "/one",
"content_group_id": 3600000
}, {
"name": "Post 2",
"meta_description": "A post worth reading",
"meta_keywords": "articles, tests, things",
"post_body": "<h1>Hey!</h1>\n<p>Some words and stuff!</p>",
"blog_author_id": 40000003,
"publish_date": 1454948562,
"slug": "/two",
"content_group_id": 3600001
}
]
}
var data = require('./articles.json').results,
req = require('superagent'),
API_KEY = process.env.API_KEY;
function run(index) {
index = index != null ? index : 0;
req.post('https://api.hubapi.com/content/api/v2/blog-posts?hapikey=' + API_KEY)
.send(data[index])
.end(function(err, res) {
if (err && err.status !== 409) {
console.log(err);
} else {
if (err && err.status === 409) {
console.log('Duplicate entry. Skipped.');
} else {
console.log('Added new post.');
}
if (data[index+1] != null) {
run(index+1);
}
}
})
}
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment