npm i
Get an Intercom access token from the Developer Hub
Copy it into export.js here:
/*
* Get a token in the Intercom developer hub https://developers.intercom.com/
*/
const token = 'YOUR TOKEN HERE';
Run with node export.js
npm i
Get an Intercom access token from the Developer Hub
Copy it into export.js here:
/*
* Get a token in the Intercom developer hub https://developers.intercom.com/
*/
const token = 'YOUR TOKEN HERE';
Run with node export.js
const fs = require('fs'); | |
const csvWriter = require('csv-writer').createObjectCsvWriter; | |
const Intercom = require('intercom-client'); | |
/* | |
* Get a token in the Intercom developer hub https://developers.intercom.com/ | |
*/ | |
const token = 'YOUR TOKEN HERE'; | |
// Replace 'your_access_token' with your actual Intercom API access token | |
const client = new Intercom.Client({ tokenAuth: { token } }); | |
async function getArticles() { | |
let articles = []; | |
let hasMore = true; | |
let nextPage = null; | |
while (hasMore) { | |
console.log(`getting page ${nextPage}`); | |
const response = await client.articles.list({ page: nextPage }); | |
articles = articles.concat(response.data); | |
hasMore = !!response.pages.next; | |
nextPage = response.pages.next; | |
} | |
return articles; | |
} | |
function saveArticlesToCsv(articles, filename = 'articles.csv') { | |
const keys = Object.keys(articles[0]); | |
const csvWriterInstance = csvWriter({ | |
path: filename, | |
header: keys.map(key => ({ id: key, title: key })), | |
}); | |
csvWriterInstance.writeRecords(articles) | |
.then(() => console.log('CSV file was written successfully')); | |
} | |
function saveArticlesToJson(articles, filename = 'articles.json') { | |
fs.writeFileSync(filename, JSON.stringify(articles, null, 4)); | |
console.log('JSON file was written successfully'); | |
} | |
(async () => { | |
try { | |
const articles = await getArticles(); | |
if (!articles.length) { | |
console.log('No articles found.'); | |
return; | |
} | |
saveArticlesToCsv(articles); | |
saveArticlesToJson(articles); | |
console.log(`Successfully exported ${articles.length} articles to CSV and JSON.`); | |
} catch (error) { | |
console.error('Error fetching articles:', error); | |
} | |
})(); | |
{ | |
"name": "intercom-export", | |
"lockfileVersion": 3, | |
"requires": true, | |
"packages": { | |
"": { | |
"dependencies": { | |
"csv-writer": "^1.6.0", | |
"intercom-client": "^5.0.0" | |
} | |
}, | |
"node_modules/asynckit": { | |
"version": "0.4.0", | |
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", | |
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" | |
}, | |
"node_modules/axios": { | |
"version": "1.7.3", | |
"resolved": "https://registry.npmjs.org/axios/-/axios-1.7.3.tgz", | |
"integrity": "sha512-Ar7ND9pU99eJ9GpoGQKhKf58GpUOgnzuaB7ueNQ5BMi0p+LZ5oaEnfF999fAArcTIBwXTCHAmGcHOZJaWPq9Nw==", | |
"dependencies": { | |
"follow-redirects": "^1.15.6", | |
"form-data": "^4.0.0", | |
"proxy-from-env": "^1.1.0" | |
} | |
}, | |
"node_modules/combined-stream": { | |
"version": "1.0.8", | |
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", | |
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", | |
"dependencies": { | |
"delayed-stream": "~1.0.0" | |
}, | |
"engines": { | |
"node": ">= 0.8" | |
} | |
}, | |
"node_modules/csv-writer": { | |
"version": "1.6.0", | |
"resolved": "https://registry.npmjs.org/csv-writer/-/csv-writer-1.6.0.tgz", | |
"integrity": "sha512-NOx7YDFWEsM/fTRAJjRpPp8t+MKRVvniAg9wQlUKx20MFrPs73WLJhFf5iteqrxNYnsy924K3Iroh3yNHeYd2g==" | |
}, | |
"node_modules/delayed-stream": { | |
"version": "1.0.0", | |
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", | |
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", | |
"engines": { | |
"node": ">=0.4.0" | |
} | |
}, | |
"node_modules/follow-redirects": { | |
"version": "1.15.6", | |
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", | |
"integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", | |
"funding": [ | |
{ | |
"type": "individual", | |
"url": "https://github.com/sponsors/RubenVerborgh" | |
} | |
], | |
"engines": { | |
"node": ">=4.0" | |
}, | |
"peerDependenciesMeta": { | |
"debug": { | |
"optional": true | |
} | |
} | |
}, | |
"node_modules/form-data": { | |
"version": "4.0.0", | |
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", | |
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", | |
"dependencies": { | |
"asynckit": "^0.4.0", | |
"combined-stream": "^1.0.8", | |
"mime-types": "^2.1.12" | |
}, | |
"engines": { | |
"node": ">= 6" | |
} | |
}, | |
"node_modules/htmlencode": { | |
"version": "0.0.4", | |
"resolved": "https://registry.npmjs.org/htmlencode/-/htmlencode-0.0.4.tgz", | |
"integrity": "sha512-0uDvNVpzj/E2TfvLLyyXhKBRvF1y84aZsyRxRXFsQobnHaL4pcaXk+Y9cnFlvnxrBLeXDNq/VJBD+ngdBgQG1w==" | |
}, | |
"node_modules/intercom-client": { | |
"version": "5.0.0", | |
"resolved": "https://registry.npmjs.org/intercom-client/-/intercom-client-5.0.0.tgz", | |
"integrity": "sha512-fEzM9w+apUwK6roDyZPvfXqmI9mrdM5Nz0QmCeDTM/8G2I0464SzJDfLTDRvz+ZkY6EIeTHEaQnK09DmYgqRhA==", | |
"dependencies": { | |
"axios": "^1.6.0", | |
"htmlencode": "^0.0.4", | |
"lodash": "^4.17.21" | |
}, | |
"engines": { | |
"node": ">= v8.0.0" | |
} | |
}, | |
"node_modules/lodash": { | |
"version": "4.17.21", | |
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", | |
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" | |
}, | |
"node_modules/mime-db": { | |
"version": "1.52.0", | |
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", | |
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", | |
"engines": { | |
"node": ">= 0.6" | |
} | |
}, | |
"node_modules/mime-types": { | |
"version": "2.1.35", | |
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", | |
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", | |
"dependencies": { | |
"mime-db": "1.52.0" | |
}, | |
"engines": { | |
"node": ">= 0.6" | |
} | |
}, | |
"node_modules/proxy-from-env": { | |
"version": "1.1.0", | |
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", | |
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" | |
} | |
} | |
} |
{ | |
"dependencies": { | |
"csv-writer": "^1.6.0", | |
"intercom-client": "^5.0.0" | |
} | |
} |