If you're interested in a Close Segment Destination, please email [email protected]. We're actively working on a Segment integration and are looking for testers in the near future. If you need something immediately you can try writing code in Functions using the code below as a starting point.
Last active
May 25, 2021 00:07
-
-
Save philfreo/34a91468ac0e2efdfbd878006066b067 to your computer and use it in GitHub Desktop.
Segment Integration JS
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
const API_BASE = 'https://api.close.com/api/v1/'; | |
const leadEndpoint = new URL(`${API_BASE}lead/`); | |
async function apiRequest(settings, endpoint, data, method = 'post') { | |
return await fetch(`https://api.close.com/api/v1/${endpoint}/`, { | |
body: JSON.stringify(data), | |
headers: new Headers({ | |
"Authorization": 'Basic ' + btoa(settings.apiKey), | |
"Content-Type": "application/json", | |
}), | |
method: "post", | |
}); | |
} | |
/** | |
* onIdentify takes an Identify event then POSTs it | |
* | |
* @param {SpecIdentify} event The identify event | |
* @param {Object.<string, any>} settings Custom settings | |
* @return any | |
*/ | |
async function onIdentify(event, settings) { | |
const res = await apiRequest(settings, 'lead', { | |
"contacts": [ | |
{ | |
"name": event.traits.name, | |
"title": event.traits.title, | |
"emails": [ | |
{ | |
"email": event.traits.email, | |
} | |
] | |
} | |
] | |
}); | |
return await res.json() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment