AppSScript Code
function fetchMozMetrics() {
var mozApiKey = "mozscape-Pxnjj9jfr3";
var mozAccessId = "";
var mozSecretKey = "czIyzlsjg0NmlG2oZ7rV0V8JLAC7TcR6";
var url = "https://api.moz.com/url-metrics";
// Specify the URL for which you want to fetch metrics
var targetUrl = "https://www.google.com";
var payload = {
"urls": [targetUrl],
"access_id": mozAccessId,
"secret_key": mozSecretKey
};
var options = {
"method": "post",
"contentType": "application/json",
"payload": JSON.stringify(payload),
"headers": {
"X-Moz-Token": mozApiKey
}
};
// Make the API request
var response = UrlFetchApp.fetch(url, options);
var responseData = JSON.parse(response.getContentText());
// Extract relevant metrics
var metrics = {
"URL": responseData[0].uu,
"Title": responseData[0].ut,
"Domain Authority": responseData[0].pda,
"Page Authority": responseData[0].upa,
"External Links": responseData[0].ueid,
"Linking Root Domains": responseData[0].uid,
"MozRank": responseData[0].umrp,
"MozTrust": responseData[0].fmrp
};
// Write metrics to the Google Sheet
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var headers = Object.keys(metrics);
var headerRow = headers.map(function(header) {
return metrics[header];
});
sheet.appendRow(headerRow);
}