Skip to content

Instantly share code, notes, and snippets.

@zerebral
Last active November 15, 2017 07:43
Show Gist options
  • Save zerebral/7c89122376620c95addcb940362e7d29 to your computer and use it in GitHub Desktop.
Save zerebral/7c89122376620c95addcb940362e7d29 to your computer and use it in GitHub Desktop.
Google Sheets Marketcheck Functions
function getDealerDomain(dealer_id) {
var url = 'http://marketcheck-prod.apigee.net/v1/dealer/'+ dealer_id + '?api_key=p3OCLOt1HQpxfp1zNVUVopAdWumsStPv';
var response = UrlFetchApp.fetch(url, {'muteHttpExceptions': true});
Logger.log(response);
return JSON.parse(response).website_s
}
function getDomainInventoryCount(domain, inventory_type) {
var url = 'http://marketcheck-prod.apigee.net/v1/search?api_key=p3OCLOt1HQpxfp1zNVUVopAdWumsStPv&source=' + domain + '&car_type=' + inventory_type;
var response = UrlFetchApp.fetch(url, {'muteHttpExceptions': true});
Logger.log(response);
return JSON.parse(response).num_found
}
function extractHostname(url) {
var hostname;
//find & remove protocol (http, ftp, etc.) and get hostname
if (url.indexOf("://") > -1) {
hostname = url.split('/')[2];
}
else {
hostname = url.split('/')[0];
}
//find & remove port number
hostname = hostname.split(':')[0];
//find & remove "?"
hostname = hostname.split('?')[0];
return hostname;
}
function toSquishVIN(vin){
if(vin.length == 10){
return vin;
}
if(vin.length == 17){
return vin.substr(0,8) + vin.substr(10, 2)
}
return "Invalid VIN - Length is not 8 or 17 letters"
}
function getTrimFromMC(vin){
var url = 'http://marketcheck-prod.apigee.net/v1/vin/' + vin + '/specs?api_key=p3OCLOt1HQpxfp1zNVUVopAdWumsStPv';
var response = UrlFetchApp.fetch(url, {'muteHttpExceptions': true});
Logger.log(response);
return JSON.parse(response).trim;
}
function getVinAuditTrim(vin){
//var vin = "1B7FL26P5XS272995";
var url = 'https://api.vinaudit.com/query.php?key=VA_MAIN&callback=VA_OnQueryData&vin=' + vin + '&try=0&mode=&rd=0.9347682183376926';
var response = UrlFetchApp.fetch(url, {'muteHttpExceptions': true});
Logger.log(response.getContentText());
return (JSON.parse(response.getContentText().match(/VA_OnQueryData\((.*)\)\;/)[1]).attributes.Trim);
}
function getSampleVIN(taxonomy_vin){
var url = 'http://marketcheck-prod.apigee.net/v1//search?api_key=p3OCLOt1HQpxfp1zNVUVopAdWumsStPv&taxonomy_vins=' + taxonomy_vin + '&start=0&rows=1'
var response = UrlFetchApp.fetch(url, {'muteHttpExceptions': true});
Logger.log(response);
return JSON.parse(response).listings[0].vin
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment