-
-
Save adam-bitium/2b75de0538098f5f7271 to your computer and use it in GitHub Desktop.
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 answers_received=' +answers + '\ | |
-d number_of_surveys=' +surveys + ' \ | |
-d number_of_campaigns=' +campaigns + ' \ | |
-d country="" \ | |
-d 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