Skip to content

Instantly share code, notes, and snippets.

@JeremyPlease
Created January 20, 2017 15:14
Show Gist options
  • Save JeremyPlease/d1580a3010175fe60e26b2a6a995cb5e to your computer and use it in GitHub Desktop.
Save JeremyPlease/d1580a3010175fe60e26b2a6a995cb5e to your computer and use it in GitHub Desktop.
Remove Custom Attributes from Intercom.io

This script fetches all users from Intercom and sets the name and address custom attributes to null.

  1. run npm i intercom-client
  2. INTERCOM_ID=id INTERCOM_API_KEY=apikey node intercom.js
var Intercom = require('intercom-client');
var client = new Intercom.Client(process.env.INTERCOM_ID, process.env.INTERCOM_API_KEY);
var updates = [];
var processed = 0;
client.users.scroll.each({}, processUsers);
function processUsers(response) {
console.log(`processed ${processed} users`);
return new Promise(function(resolve, reject) {
response.body.users.forEach(function(user, i) {
processed++;
var lastItem = (i == (response.body.users.length - 1));
if (user.name || user.address) {
updates.push({ post: {
id: user.id,
name: null,
custom_attributes: {
name: null,
address: null
}
}});
}
if (updates.length == 100 || lastItem) {
if (!updates.length) {
return resolve();
}
client.users.bulk(updates, function(e, r) {
if (e) {
reject(e);
}
if (i == (response.body.users.length - 1)) {
resolve();
}
});
updates = [];
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment