script returns
I am trying to get the attendance not taken for today, but this script returns:
{"statusCode":401,"message":"The required Authorization header was missing or invalid, or the token has expired","status":401,"title":"The required Authorization header was missing or invalid, or the token has expired"}
Any advice?
Thank you very much!
SCript:
function fetchAndUpdateAttendanceData() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Attendance Not Taken Today");
// Clear previous data except for the header row
if (sheet) {
var lastRow = sheet.getLastRow();
if (lastRow > 1) {
sheet.getRange(2, 1, lastRow - 1, sheet.getLastColumn()).clearContent();
}
}
// Correct the apiUrl construction (ensure correct concatenation)
var listId = 86555;
var apiUrl = 'https://api.sky.blackbaud.com/school/v1/lists/advanced/' + listId; // Ensure the list endpoint is correct
// Add your API subscription key here
var subscriptionKey = 'a06a7d071baa44xxxxxxx36b6984fb'; // Replace with your actual subscription key, keep it secure
// Set up headers for the API request with the correct key name
var options = {
'method' : 'GET',
'headers': {
'Bb-Api-Subscription-Key': subscriptionKey, // The correct header for Blackbaud's SKY API
'Content-Type': 'application/json'
},
'muteHttpExceptions': true // Allows full error response to be logged
};
// Fetch the attendance data
try {
var response = UrlFetchApp.fetch(apiUrl, options);
// Log the full response (will help identify exact error or confirm success)
Logger.log(response.getContentText()); // This will log the entire response, including error details
// Parse the response
var data = JSON.parse(response.getContentText());
// Assume 'data' is an array of attendance records (adapt this if structure differs)
var attendanceRecords = data.value || []; // Replace with actual response structure
// Populate the sheet with new data
if (attendanceRecords.length > 0) {
for (var i = 0; i < attendanceRecords.length; i++) {
var row = attendanceRecords[i];
sheet.appendRow([row.studentName, row.status, row.time]); // Replace with your fields
}
} else {
Logger.log('No attendance records found.');
}
} catch (e) {
Logger.log("Error fetching attendance data: " + e.toString());
}
}
Comments
-
0
Categories
- All Categories
- 6 Blackbaud Community Help
- 213 bbcon®
- 1.4K Blackbaud Altru®
- 402 Blackbaud Award Management™ and Blackbaud Stewardship Management™
- 1.1K Blackbaud CRM™ and Blackbaud Internet Solutions™
- 15 donorCentrics®
- 360 Blackbaud eTapestry®
- 2.6K Blackbaud Financial Edge NXT®
- 655 Blackbaud Grantmaking™
- 576 Blackbaud Education Management Solutions for Higher Education
- 3.2K Blackbaud Education Management Solutions for K-12 Schools
- 939 Blackbaud Luminate Online® and Blackbaud TeamRaiser®
- 84 JustGiving® from Blackbaud®
- 6.6K Blackbaud Raiser's Edge NXT®
- 3.7K SKY Developer
- 248 ResearchPoint™
- 119 Blackbaud Tuition Management™
- 165 Organizational Best Practices
- 241 Member Lounge (Just for Fun)
- 34 Blackbaud Community Challenges
- 34 PowerUp Challenges
- 3 (Open) PowerUp Challenge: Chat for Blackbaud AI
- 3 (Closed) PowerUp Challenge: Data Health
- 3 (Closed) Raiser's Edge NXT PowerUp Challenge: Product Update Briefing
- 3 (Closed) Raiser's Edge NXT PowerUp Challenge: Standard Reports+
- 3 (Closed) Raiser's Edge NXT PowerUp Challenge: Email Marketing
- 3 (Closed) Raiser's Edge NXT PowerUp Challenge: Gift Management
- 4 (Closed) Raiser's Edge NXT PowerUp Challenge: Event Management
- 3 (Closed) Raiser's Edge NXT PowerUp Challenge: Home Page
- 4 (Closed) Raiser's Edge NXT PowerUp Challenge: Standard Reports
- 4 (Closed) Raiser's Edge NXT PowerUp Challenge: Query
- 792 Community News
- 2.9K Jobs Board
- 54 Blackbaud SKY® Reporting Announcements
- 47 Blackbaud CRM Higher Ed Product Advisory Group (HE PAG)
- 19 Blackbaud CRM Product Advisory Group (BBCRM PAG)