I have a question regarding a nodejs link scraper bot that I'm working on. The bot scrapes a url and adds it to a Monbodb database.
I want to automatically fill a google sheets file with the date/url of each link that the bot scrapes.
The bot is working fine and posts the dates/url to the Mongodb database.I followed this guide to a T, https://www.lido.app/tutorials/connect-mongodb-atlas-database-to-google-sheets-via-google-apps-script and I am getting this error when running/debugging my code.
It leads me to believe there is something wrong with the URL endpoint that I copy pasted from Mongodb cloud? I followed the guide exactly and there is no other link to copy so I was pretty sure this is correct. Is there something wrong with the syntax, or?
Thank you for the assistance I appreciate it! :)
Error: line 77 | const response = UrlFetchApp.fetch(findEndpoint,
options);
The entire code that I input to google sheets apps script is as follows...
const findEndpoint = 'MY MONGODB URL ENDPOINT';
const clusterName = "Cluster0"
const apikey = "MY API KEY"
function lookupInspection() {
const activeSheetsApp = SpreadsheetApp.getActiveSpreadsheet();
const sheet = activeSheetsApp.getSheets()[0];
const partname = sheet.getRange("B1").getValue();
const limit = sheet.getRange("D1").getValue();
const skips = sheet.getRange("F1").getValue();
const orderopt = sheet.getRange("H1").getValue();
var orderr = 0;
sheet.getRange(`A4:I${limit+3}`).clear()
if (orderopt == "Ascending") {
orderr=1;
} else if (orderopt == "Descending") {
orderr=-1;
}
//We can do operators like regular expression with the Data API
const query = { business_name: { $regex: `${partname}`, $options: 'i' } }
const order = { business_name: orderr }
//We can Specify sort, limit and a projection here if we want
const payload = {
filter: query, sort: order, limit: limit, skip: skips,
collection: "test", database: "posts", dataSource: clusterName
}
const options = {
method: 'post',
contentType: 'application/json',
payload: JSON.stringify(payload),
headers: { "api-key": apikey }
};
const response = UrlFetchApp.fetch(findEndpoint, options);
const documents = JSON.parse(response.getContentText()).documents
// logUsage(partname, documents.length, apikey); //Log Usage
for (d = 1; d <= documents.length; d++) {
let doc = documents[d - 1]
fields = [[doc.business_name, doc.date, doc.result, doc.sector,
doc.certificate_number, doc.address.number,
doc.address.street, doc.address.city, doc.address.zip]]
let row = d + 3
sheet.getRange(`A${row}:I${row}`).setValues(fields)
}
}
enter image description here