Created
November 20, 2012 11:29
-
-
Save nicolasembleton/4117402 to your computer and use it in GitHub Desktop.
Import your customer data with custom parameters into customer.io
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//#!/usr/bin/env node | |
var http = require("http"), | |
fs = require("fs"), | |
sys = require('sys'), | |
exec = require('child_process').exec; | |
var ENDPOINT="https://app.customer.io/api/v1/customers/"; | |
var SITEID="YOUR SITE ID"; | |
var APIKEY="YOUR API KEY"; | |
var path = "./users.csv"; | |
var delimiter = ","; | |
var cnt = 0; | |
var cmd_queue = []; | |
/** Helper to output the curl command stdout */ | |
function puts(error, stdout, stderr) { | |
// Some output for debugging purposes | |
console.log("Command: " +cnt); | |
sys.puts(stdout); | |
// Next command in the chain | |
cnt++; | |
if(cnt < cmd_queue.length) { | |
exec(cmd_queue[cnt], puts); | |
} | |
} | |
fs.readFile("./users.csv", function(err, data) { | |
if (err) throw err; | |
// Be careful with the new line character, excel outputs \r | |
var lines = data.toString().split("\r"); | |
for(var line in lines) { | |
var spread = lines[line].split(delimiter); // CSV delimiter | |
// console.log(spread); | |
var account_id = spread[0], | |
account_email = spread[1], | |
user_id = spread[2], | |
email = spread[3], | |
created_at = spread[4], | |
surveys = spread[5], | |
answers = spread[6], | |
campaigns = spread[7], | |
plan = spread[8]; | |
cmd_queue[line] = ' \ | |
curl -i ' +ENDPOINT +user_id + ' \ | |
-X PUT \ | |
-u ' +SITEID +':' +APIKEY +' \ | |
-d created_at=' +created_at + ' \ | |
-d email=' +email +' \ | |
-d id=' +user_id +' \ | |
-d plan=' +plan + ' \ | |
-d data[answers_received]=' +answers + '\ | |
-d data[number_of_surveys]=' +surveys + ' \ | |
-d data[number_of_campaigns]=' +campaigns + ' \ | |
-d data[country]="" \ | |
-d data[language]="EN" \ | |
'; | |
// console.log(command); | |
} | |
// trigger the first cmd chain | |
exec(cmd_queue[0], puts); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think that with recent improvements in customer.io APIs, this:
Can be written:
There is no longer a need for data[] array wrapper