Last active
February 12, 2021 17:34
-
-
Save ZeldOcarina/897464878c0f1df0c1ee8142c9d40e4b to your computer and use it in GitHub Desktop.
A Javascript function to connect any external app to Sales Jet.
This file contains 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
// USE THIS FUNCTION TO CONNECT ANY EXTERNAL APP TO SALES JET: | |
async function submitToSalesJet(api_key, event_name, email, first_name, last_name) { | |
try { | |
const response = await fetch("https://sj-api.com/externalapp/track", { | |
method: "POST", | |
headers: { | |
"Content-Type": "application/json", | |
Authorization: api_key // YOUR API KEY GOES HERE | |
}, | |
body: JSON.stringify({ | |
event_name: event_name, // YOUR EVENT NAME GOES HERE, | |
contact: { | |
email: email, // Your email field | |
first_name: first_name, //Your first name field | |
last_name: last_name // Your last name field | |
phone_number: phone_number // Your phone number field | |
custom_attributes: { | |
"dc7627c8-b33f-eb11-a9a9-c26375d3e59f": data.subject, // Custom attribute UUID goes here | |
"451d9d75-b43f-eb11-a9a9-c26375d3e59f": data.message // Custom attribute UUID goes here | |
} | |
}, | |
}), | |
}); | |
// YOU CAN GET HOLD OF THE RESPONSE OBJECT FROM SALES JET TO CHECK IF THE CONNECTION WAS SUCCESSFUL: | |
console.log(response); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This function uses native
fetch
to connect any external app to Sales Jet. Feel free to refactor this with any AJAX util you like.