Bot cant open Google Spreadsheets? Error 403

Hi, i'm quite new javascript and node and djs, I'm trying to make a slashCommand to see a spreadsheet however its not detecting? My code is below but the error message im getting is in the ss I'v tried: - testing my slashCommand file(regionals.js) separately from fetchSheetData - Giving my API key even though the spreadsheet is public - not giving my API key All have the same error code My code: - in: ./src/utils/sheetData.js
const baseSheetUrl = "https://sheets.googleapis.com/v4/spreadsheets/";

/**
* Fetches data from a specific Google Sheets range.
* @param {string} SHEET_ID - The ID of the Google Sheet.
* @returns {Promise<Object>} - A promise that resolves to the sheet data.
*/
async function fetchSheetData() {
const SHEET_ID = '1eqb7Zx7snlGYnRAPsd2uky7slXx5BhaAkfu2ZTWtUdg'; // you can find this in the URL at https://docs.google.com/spreadsheets/d/-->SHEET_ID<--/edit?gid=0#gid=0
const sheetTab = "WEEK1-CanadianPacific"; // The sheet tab is on the bottom left
const range = `${sheetTab}!B7:B16,E7:E16`;


const fetch = (await import("node-fetch")).default;

const sheetUrl = `${baseSheetUrl}${SHEET_ID}/values/${range}?key=${require("../../config.json").API_KEY}`; // an API key is not needed if anyone with the link can view

const response = await fetch(sheetUrl, {
method: "GET",
headers: {
accept: "application/json",
},
});

if (!response.ok) {
console.error(`Failed to fetch data: ${response.status} ${response.statusText}`);
throw new Error("Failed to fetch data from Google Sheets.");
}

return response.json();
}

module.exports = fetchSheetData;
const baseSheetUrl = "https://sheets.googleapis.com/v4/spreadsheets/";

/**
* Fetches data from a specific Google Sheets range.
* @param {string} SHEET_ID - The ID of the Google Sheet.
* @returns {Promise<Object>} - A promise that resolves to the sheet data.
*/
async function fetchSheetData() {
const SHEET_ID = '1eqb7Zx7snlGYnRAPsd2uky7slXx5BhaAkfu2ZTWtUdg'; // you can find this in the URL at https://docs.google.com/spreadsheets/d/-->SHEET_ID<--/edit?gid=0#gid=0
const sheetTab = "WEEK1-CanadianPacific"; // The sheet tab is on the bottom left
const range = `${sheetTab}!B7:B16,E7:E16`;


const fetch = (await import("node-fetch")).default;

const sheetUrl = `${baseSheetUrl}${SHEET_ID}/values/${range}?key=${require("../../config.json").API_KEY}`; // an API key is not needed if anyone with the link can view

const response = await fetch(sheetUrl, {
method: "GET",
headers: {
accept: "application/json",
},
});

if (!response.ok) {
console.error(`Failed to fetch data: ${response.status} ${response.statusText}`);
throw new Error("Failed to fetch data from Google Sheets.");
}

return response.json();
}

module.exports = fetchSheetData;
No description
4 Replies
d.js toolkit
d.js toolkit4w ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by staff
Julius
JuliusOP4w ago
node -v version: 22.11.0 djs list: 14.16.3
duck
duck4w ago
this doesn't seem discord.js related, but rather just about fetching from google docs
Not a discord.js issue? Check out #other-js-ts.
Julius
JuliusOP4w ago
ah, so sorry.. like I said im new to programming so I really wasnt sure what it is

Did you find this page helpful?