This script fetches all users from Intercom and sets the name and address custom attributes to null.
- run
npm i intercom-client 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 = []; | |
| } | |
| }); | |
| }); | |
| } |