Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save HubSpotHanevold/9d69f6b7210a8380a7cdf2b6c4758ee7 to your computer and use it in GitHub Desktop.
Save HubSpotHanevold/9d69f6b7210a8380a7cdf2b6c4758ee7 to your computer and use it in GitHub Desktop.
const request = require('request');
exports.main = async (event, callback) => {
const email = event.inputFields['email'];
let domain = email.split('@')[1];
let username = email.split('@')[0];
var options = {
'method': 'GET',
'url': 'https://api.hubapi.com/hubdb/api/v2/tables/5486243/rows?name=' + domain,
'headers': {
'Authorization': 'Bearer ' + process.env.HUBDBKEY
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
const obj = JSON.parse(response.body);
let corrected_domain = obj.objects[0].values['2'];
let corrected_email = username + '@' + corrected_domain;
callback({
outputFields: {
former_email: email,
corrected_domain: corrected_domain,
corrected_email: corrected_email
}
});
});
}
@HubSpotHanevold
Copy link
Author

HubSpotHanevold commented Sep 22, 2022

Preview of custom coded action output:
Link to Preview

@HubSpotHanevold
Copy link
Author

Create a hubdb table with the domain misspellings and corrected domains.
Create a list of contacts with domain misspellings (filter by email contains misspelling)
Create a workflow with trigger being member of said list ^
Custom coded action that splits username from domain, looks up misspelled domain in hubdb, then returns corrected domain
Append username back to corrected domain and output the corrected email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment