Last active
September 15, 2022 21:14
-
-
Save HubSpotHanevold/b3f4cc287b2392b5f349051a2ab49f29 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
const request = require('request'); | |
exports.main = async (event, callback) => { | |
/* BE SURE TO ADD THE POSTAL CODE INTO THE 'PROPERTY TO INCLUDE IN CODE' SECTION OF THE CUSTOM CODED ACTION */ | |
const zip_code = event.inputFields['zip']; | |
/* LOOK UP THE CITY AND STATE VIA THE ZIP CODE AND RETRIEVE THE PROPERTY 'zip' */ | |
/* ZIPAPIKEY IS USING THE FREE ZIP CODE LOOKUP SERVICE HERE: https://zipapi.us/ */ | |
var options = { | |
'method': 'GET', | |
'url': 'https://api.hubapi.com/hubdb/api/v2/tables/5470790/rows?orderBy=geo_distance(location,' + lat + ',' + lon + ')', | |
'headers': { | |
'Authorization': 'Bearer ' + process.env.HUBDBKEY | |
} | |
}; | |
request(options, function (error, response, body) { | |
const obj = JSON.parse(body); | |
/* ASSIGN city AND state TO VARIABLES FROM THE RETURNED JSON RESPONSE */ | |
let city = obj.data.city; | |
let state = obj.data.state; | |
/* DON'T FORGET TO ADD THE TWO CALLBACK OUTPUT FIELDS INTO THE DATA OUTPUTS SECTION OF YOUR CUSTOM CODED ACTION. YOU CAN USE THESE VALUES TO DETERMINE NEXT STEPS IN YOUR WORKFLOW */ | |
callback({ | |
outputFields: { | |
returned_city: city, | |
returned_state: state, | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment