Last active
January 25, 2018 23:09
-
-
Save egorvinogradov/025934be6b7b8149cca3855f509b8b78 to your computer and use it in GitHub Desktop.
Vervoe.com mass invite via CSV upload is not working. This code pushes invitees to Vervoe directly through their REST API
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
function makeRequestBody(rows, jobSlug){ | |
var paramArr = []; | |
for (var i = 0; i < rows.length; i++) { | |
var name = rows[i].name.replace(/\s+/g, '+'); | |
var email = encodeURIComponent(rows[i].email); | |
var nameS = `%22invitation_name${i + 1}%22%3A%22${name}%22`; | |
var emailS = `%22invitation_email${i + 1}%22%3A%22${email}%22`; | |
paramArr.push(`${nameS}%2C${emailS}`); | |
} | |
return `slug=${jobSlug}&form=%7B${paramArr.join('%2C')}%7D`; | |
} | |
function inviteUsers(users, jobSlug){ | |
var data = makeRequestBody(users, jobSlug); | |
fetch('https://leadforcareer.vervoe.com/api/sourceColumn/invite', { | |
method: 'POST', | |
body: data, | |
headers: new Headers({ | |
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' | |
}), | |
credentials: 'same-origin', | |
}) | |
.then(res => res.json()) | |
.catch(error => {console.error('Error:', error); window._e = error}) | |
.then(response => {console.log('Success:', response); window._r = response}); | |
} | |
// Format: | |
// var users = [ | |
// {name: 'name 5', email: '[email protected]'}, | |
// {name: 'name 6', email: '[email protected]'}, | |
// {name: 'name 7', email: '[email protected]'}, | |
// {name: 'name 8', email: '[email protected]'}, | |
// ]; | |
// | |
// Copypaste into the browser console: | |
// inviteUsers(users, 'frontend-software-engineer-reactjs-remote'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment